0

I've spent the past few days trying different variations of if statements to get this working but it's now driving me nuts.

What I'd like to do is show a series of divs on the first page of a custom component but not on any other pages 2, 3, etc.

I'm using Joomla 4 with the custom component.

This is my current code which is producing errors.

<?php if ($this->app->getInput()->getInt('start') < 1) : ?>
    Hello World
<?php : ?>

edit More information

For instance, the following code is to display items from the database in the component.

<div class="everistBlock featured">
            <?php $i = 0; foreach ($this->items as $i => $item) : if ($i == 15) {break;} ?>
                <?php if ($item->articletype=="Featured Article") : ?>
                    <div class="featuredContainer">
                        <div class="newsItem"> 
                            <div class="newsItemImage">
                                <img src="<?php echo $item->articleimage; ?>" alt="<?php echo $item->title; ?>">
                            </div>
                            <div class="newsItemTitle">
                                <a href="<?php echo Route::_('index.php?option=com_everist&view=newsarticle&id='.(int) $item->id); ?>"><?php echo $this->escape($item->title); ?></a>
                            </div>
                        </div>
                    </div>
                <?php endif ?>
            <?php $i++; endforeach ?>
        </div>

What I would like to do is have more like this but starting on page 2, or only visible on page 1.

5
  • 1
    Hello and welcome! Can you show also what error do you get? Jan 22 at 8:55
  • It's just a blank page I get (white screen of death) on the specific page.
    – Apatchie
    Jan 22 at 10:24
  • 1
    Did you turn on the error reporting and debug? If not, do it for see what error show up. Jan 22 at 20:24
  • 1
    We need more information. Is this admin or site? Is this code in display tmpl file or the source view file? I'll make some assumptions for the response below. Jan 22 at 23:33
  • I've updated the question with further information.
    – Apatchie
    Jan 23 at 9:05

2 Answers 2

1

You need to get the Pagination object rather than trying to derive it from the input variables.

In your HtmlView file:

$this->pagination = $this->get('pagination');

Then in your tmpl file, you can ask the pagination which page you're on:

if($this->pagination->pagesCurrent == 1) {
    //Do whatever you want for the first page
} else {
    //Alternative content for other pages
}
1
  • This worked perfectly. Thank you! Could I also ask, how can I reset the count. For instance, articles showing on page 1 - how would I get these to show on page 2 as well as if page 2 is the start.
    – Apatchie
    Jan 28 at 11:00
0

In the Source View file (src/View/HtmlView.php) you possibly have this in the display function:

$this->pagination = $this->get('Pagination');

Then in the multiples listing tmpl file you would have something like:

<tfoot>
    <tr>
        <td colspan="10">
            <?php echo $this->pagination->getListFooter(); ?>
        </td>
    </tr>
</tfoot>
1
  • This is to generate the pagination, not to create a control for what page something will appear on.
    – Apatchie
    Jan 23 at 6:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.