Sending Parameters to A Page & Trapping them With Smarty

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Sending Parameters to A Page & Trapping them With Smarty

Post by calguy1000 »

the cms_selflink page allows you to add parameters to the URL so that logic  on the destination page can detect the parameters and display different things.

i.e add some content like this to a page:

Code: Select all

{cms_selflink page='testpage' text='do this' urlparam='&mode=dothis'}
{cms_selflink page='testpage' text='do that' urlparam='&mode=dothat'}
Now when you refresh this page, you will see that the mode= parameter is added on to each of these links to the CMS testpage page.

Creating a page with the alias 'testpage', I then add code like this:

Code: Select all

{if $smarty.get.mode == 'dothis'}
    <h3>Do That</h3>
{elseif $smarty.get.mode == 'dothat'}
    <h3>Do This</h3>
{else}
    <strong>Error Unknown Mode</strong>
{/if}
Going directly to this page, should tell you about an unknown mode
however, using one of the links created above should display different text.

This could be useful for re-using the same detail page to display different forms, or for a variety of purposes.

Just thought I'd pass on this little tip.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm

Re: Sending Parameters to A Page & Trapping them With Smarty

Post by Nullig »

Excellent tip. I can see myself using this quite a bit.

Nullig
Post Reply

Return to “Tips and Tricks”