We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Tag parameters inside an if statement

How Do I?

jthane's avatar
jthane
3 posts
6 years ago
jthane's avatar jthane

I’m trying to write a conditional statement depending on whether a tag returns anything. The catch is that the tag includes a parameter based on a variable. This is what I’m trying:

{if exp:seo:title entry_id="{entry_id}"}{exp:seo:title entry_id="{entry_id}"}{if:elseif title}{title}{if:else}{site_name}{/if}

Which results in an error:

You have an invalid conditional in your template. Please review your conditionals for an unclosed string, invalid operators, a missing }, or a missing {/if}.

Parser State: Unexpected ‘entry_id’ (VARIABLE); expected RD in Template “main/interior-primary-left” on line 8.

I feel like I’m probably doing something dumb. Help is appreciated!

       
James Mathias's avatar
James Mathias
225 posts
6 years ago
James Mathias's avatar James Mathias

Hi,

I’m not familiar with the tag exp:seo:title, but conditionals can’t have parameters on them so the opening if tag would need to be {if exp:seo:title}

       
jthane's avatar
jthane
3 posts
6 years ago
jthane's avatar jthane

Thanks for the answer! Given that the entry_id parameter is required in order to specify which entry to pull the SEO title for, is there any way to accomplish what I’m trying to do?

       
James Mathias's avatar
James Mathias
225 posts
6 years ago
James Mathias's avatar James Mathias

Is the exp:seo:title tag coming from an add on? If yes I would recommend checking their documentation to see if they have a way to handle it with that add on.

I assume you are trying to set up the meta title tag for your site to be more dynamic based on the page you’re visiting. If that is the case, I would recommend using a custom field in your channel, and layouts in the template allowing you to have more control. Instead of an add on.

In example I typically create an seo_title in my Channel. Then in the template I pass that value to a Layout Set

{exp:channel:entries channel='channel_name'}
 {layout:set name='meta_title'}
  {if seo_title}
   {seo_title}
  {if:else}
   {title}
  {/if}
 {/layout:set}
{/exp:channel:entries}

Then in the Layout itself I do this

<!-- meta data, per page -->
<title>{if layout:meta_title}{layout:meta_title} {if segment_1}/ {/if}{/if}{site_name}</title>
       
jthane's avatar
jthane
3 posts
6 years ago
jthane's avatar jthane

Right on, thanks. Unfortunately the documentation for the plugin is…sparse. I’ll consider switching to just using channel fields like you suggest.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.