5

I've got OpenCart and theme using twig, how can I display my text only at the first page of the category and do not show it at the pagination pages.

My template looks like this

{% if description %}
    <div class="row" style="margin-bottom:50px;">
        {{ description }}
    </div>
{% endif %}
focus.style
  • 5,674
  • 4
  • 18
  • 34
Danyl
  • 61
  • 4

2 Answers2

3

This check should not be executing in .twig template. This is a task for controller.

Go to catalog/controller/product/category.php

Find

$data['description'] = html_entity_decode($category_info['description'], ENT_QUOTES, 'UTF-8');

Replaced it with

if ($page == 1) {
    $data['description'] = html_entity_decode($category_info['description'], ENT_QUOTES, 'UTF-8');
} else {
    $data['description'] = '';
}

Tested, works perfect. No template edition needed. Restore your .twig file to the original condition.

If you don't see any changes - clear caches according to this instruction https://stackoverflow.com/a/61524855/3187127


UPDATED

Or, if you want to check anything else in template

Go to catalog/controller/product/category.php

Find

if (isset($this->request->get['page'])) {
    $page = $this->request->get['page'];
} else {
    $page = 1;
}

Add below

if ($page == 1) {
    $data['firstpage'] = 1;
} else {
    $data['firstpage'] = '';
}

Now on your catalog/view/theme/YOUR_THEME/template/product/category.twig you can make check like this

{% if firstpage %}
    This is the first page.
{% endif %}

UPDATED 2 After previous manipulation your code should be like this

if (isset($this->request->get['page'])) {
    $page = $this->request->get['page'];
} else {
    $page = 1;
}

if ($page == 1) {
    $data['firstpage'] = 1;
} else {
    $data['firstpage'] = '';
}
focus.style
  • 5,674
  • 4
  • 18
  • 34
  • deletet aproved all the data from the page , i mean main content products plus discription text . )))))) So i dont think thats decision for me – Danyl Jun 18 '20 at 11:10
  • Didn't understand. Can you show, what concert data do you wan't to show only on first page? – focus.style Jun 18 '20 at 11:14
  • Updated the answer, look please. – focus.style Jun 18 '20 at 11:23
  • Thanks for helping me but its still doesnt work . Says unexpected ElSE at category.php – Danyl Jun 18 '20 at 12:51
  • I think you missed something. Updated the answer. There is a code as it should be. You only needed to add code to controller, not to replace it. Please, check very-very carefully. every step i describe. I checked everything and it works fine. – focus.style Jun 18 '20 at 13:58
  • Thanks man . I literally make all the steps as you describe and nothing going on. Im not able to test it one more time atm, but ill make it later in a few hours . So stay in contact. – Danyl Jun 18 '20 at 14:48
  • Ok. I'm here all the time – focus.style Jun 18 '20 at 14:49
0

If I'm correct you should be able to fetch the querysting parameter page inside twig with opencart like this:

{{ app.request.query.get('page') }}

You could use this to test if your at the first page of your pagination with

{% if app.request.query.get('page')|default(1) == 1 %}
     You are at the first page
{% endif %}
DarkBee
  • 13,798
  • 5
  • 41
  • 53
  • what if ive got parametr at the end of the string .....page=2 ?)) – Danyl Jun 18 '20 at 09:40
  • Yeah i mean ive got url like this https://somesite.com/topic?page=2 . Should your solution works ? Or need to change something ? Thanks – Danyl Jun 18 '20 at 10:01
  • Well guess so yeah. The message will be shown if `?page` is not present or `page=1`. That is what you wanted right? – DarkBee Jun 18 '20 at 10:03
  • Ive tried it but seems it doesnt work for me, and then i forgot to say that ive got parameter in the end of the url string . But its only at the pagination pages. The first page looks like somesite.com/topic and other pagination pages are - somesite.com/topic?page=2 (3,4 and other).My case was like to show text at the first page and do not show at other. – Danyl Jun 18 '20 at 10:10
  • You've copied/pasted the `if` right and not the first line i've added? – DarkBee Jun 18 '20 at 10:16