Problem in links being generated with [[+page]]

Hi,

I have a following code in my getPage call,

                [[getPage?
                &element=`getResources`
                &parents=`7, 23, 24, 25, 49, 51, 52, 113`
                &limit=`4`
                &includeTVs=`1`
                &processTVs=`1`
                &sortby=`menuindex`
                &sortdir=`ASC`
                &tpl=`product-list`
                &totalVar=`total`
                &pagePrevTpl=`<li class="pagination-prev"><a href="[[++site_url]][[+href]]"><span class="zn_icon" data-zniconfam="glyphicons_halflingsregular" data-zn_icon="ī‰—"></span></a></li>`
                &pageNextTpl=`<li class="pagination-next"><a href="[[++site_url]][[+href]]"><span class="zn_icon" data-zniconfam="glyphicons_halflingsregular" data-zn_icon="ī‰˜"></span></a></li>`
                &pageActiveTpl=`<li class="active" class="page-[[+pageNo]]"><span style="display: inline-block;">[[+pageNo]]</span></li>`
                &pageNavTpl=`<li><a href="[[+href]]"><span>[[+pageNo]]</span></a></li>`
                &pageNavOuterTpl=`[[+prev]][[+pages]][[+next]]`
				&pageNavVar=`page.nav`
				&toPlaceholder=`products`
                ]]

There is problem in the
&pageNavOuterTpl=[[+prev]][[+pages]][[+next]]
as the +pages is giving me list withing ul li structure of urls like {http:://host}/products/products/?page=3 ā€¦ is there a perfect way to remove ā€˜/products/products/ā€™ from the url ? I know its an easy hack but I could not figure this out. If it would be WordPress, this thing would have be solved quite earlier. I could not rewrite it in .htaccess and I could not find the +pages source inside the code to hack around.

Thanks,
Ronak

Does your [[++site_url]] tag contain the products/ URI?

Also getPage should always be called uncached or it wonā€™t work properly so make sure you put a ! in front like this: [[!getPage?

Hi @digitalpenguin, thanks for the reply.

No, [[+site_url]] does not contain prodcuts/ in URI thats why I have used it in the &pagePrevTpl and &pageNextTpl as they are direct links but [+pages] give me the whole list based html structure, so I am not able to use [[+site_url]] there.

Thanks,
Ronak

Hmmm I think I misunderstood your question. So itā€™s not actually products/products in the URI right?
You are just looking for a way to remove the path?

Thereā€™s not an out of the box way of doing that for just the getPage snippet.

However if you want all links to be like that, you can set the system setting use_alias_path to No.

Or if you want specific pages to be like that, on the resource in question, go to the settings tab and click Freeze URI then enter the URI you want that page to have.

Or if you have a bunch of resources all under the same parent where you donā€™t want the parentā€™s alias in the path then go to the settings tab on the parent and uncheck Use current alias in alias path.

I am using MODX Revolution.

  1. use_alias_path is already no in the system settings

  2. I have also tried to freeze the URI to products/ but it also does not solve this

  3. I am not sure why but I do not see ā€œcurrent alias in alias pathā€ thing in the parentā€™s settings. So currently the situation is the same ā€¦ rather than next and previous links which I have created with [[++site_url]], the inner links of the pages in pagination becomes

[[++site_url]]/products/products/?page=2

  1. If thatā€™s set to no then I donā€™t think itā€™s the MODX core thatā€™s creating those paths. I would check if youā€™ve got any custom plugins installed or if thereā€™s something in an htaccess file causing it.

  2. What happened when you tried?

  3. What version of MODX are you running?

Yeah !! This is solved. use_alias_path and [[++site_url]] were the key things. Really thanks to @digitalpenguin I would not have ever come to know about use_alias_path had set to No without your answer. It was correct setting but because not knowing it, I was thinking that there is an issue in permalink that it removes /products in general from between whereas its coming in the shop page, getPage call gives it to products link. So I was thinking in that direction but I was wrong.

The /products removal from link was purpose full but strangely, getPage call does not reflect this setting and gives /products in between.

Solution

&pageNavTpl=<li><a href="[[+href]]"><span>[[+pageNo]]</span></a></li>

was changed to ā€¦

&pageNavTpl=<li><a href="[[++site_url]][[+href]]"><span>[[+pageNo]]</span></a></li>

and same as in product-list chunk ā€¦

href="[[~[[+id]]]]"

was changed to ā€¦

href="[[++site_url]][[~[[+id]]]]"
and it was done !!

1 Like

Glad you got it working!

Just wondering, do you have <base href="[[!++site_url]]" /> in your template head section?
If not, that could be a reason relative links are not working.

Also instead of using [[++site_url]] in your link, you should be able to use [[~[[+id]]? &scheme=`full`]]

Yes, <base href="[[!++site_url]]"> is right there in my head section ā€¦ do it need to be
<base href="[[!++site_url]]" /> ?

Secondly, [[~[[+id]] was right there in my product-list chunk but I had to put [[++site_url]][[~[[+id]] then only it worked as expected. So, [[~[[+id]]? &scheme=full]] would be the more correct one right ?

Thanks,
Ronak

The secondary site_url before [[+id]] should not be necessary now that you have the site_url properly in your head section. By default Modx will look for the site url and a couple of settings to know the domain name. It could even cause an error I believe.

Also, with system settings they are a blessing and a bit of a curse. They make lots of things incredibly easy, but you absolutely have to know the most important ones, because if they change, things will break. Back to the good side, you can even make your own custom system settings!

Yeah having having <base href="[[!++site_url]]"> in your page head section should allow relative links to work. So you shouldnā€™t need to put [[++site_url]] at the beginning of a link.

Using the &scheme=`full` (or &scheme=`abs`) parameter creates the full link instead of a relative one.