Inside this URL there is a parameter:
http://localhost/recipe?id=9
Is it possible to use this parameter (id=9)
with a conditional, like a segment? Or to check if there is a parameter inside a URL or not?
ExpressionEngine® Answers is a question and answer site for administrators, end users, developers and designers for ExpressionEngine® CMS. It only takes a minute to sign up.
Sign up to join this communityYou can easily retreive GET and POST variables with the Mo' Variables add-on.
Download from Devot-ee
Github repository
For example, if your URL is http://localhost/recipe?id=9
, you could use this code in your recipe/index
template:
{if get:id == "9"}
TRUE!
{/if}
You can also create default values for variables in the extension settings to test conditionals if no id parameter exists. For instance, if the default value for "id" is 0:
{if get:id != 0}
ID EXISTS!
{if:else}
No ID here!
{/if}
This is useful for handling exceptions like if there is no value in the query string (/recipe?id=
).
{if {get:id} == "9"}
works fine. So does {if get:id == "9"}. And even {if {get:id} == 9}
if you only ever expect an integer as the value. But I usually try using quotes and curly braces as part of my troubleshooting process because they tend work more often especially for complicated logic. Reading thru this related question, it seems like there is not clear consensus on the issue: expressionengine.stackexchange.com/q/7/153
Mar 18, 2014 at 20:29
With mo' variables (http://devot-ee.com/add-ons/mo-variables) you can get your get/post vars into early parsed variables you can then use in standard conditionals.
The URL Helper add-on is also worth mentioning, and will give you access to the query string within your templates.