Jump to content

Structured Data & Smarty tags


Sonu2007

Recommended Posts

There is way so i can use smarty tags inside structural data syntax? something like

<script type="application/ld+json"> { 
"@context" : "http://schema.org",
"@type" : "Organization",
"name":"{$title}",
"description": "{$desc}",
Above code return output as following instead of actual site title and description

"name":"{$title}"

"description": "{$desc}"

 

 

Link to comment
Share on other sites

  • WHMCS Developer

The issue here is smarty's intelligent recognition that you are running javascript.

Try replacing your { in the first line with {$ldelim} - see https://www.smarty.net/docs/en/language.function.ldelim.tpl#idp36077424 for the full Smarty documentation

<script type="application/ld+json"> {$ldelim} 
"@context" : "http://schema.org",
"@type" : "Organization",
"name":"{$title}",
"description": "{$desc}",
  
  
....
{$rdelim}

 

Link to comment
Share on other sites

Non of them are working, my following code print as it is

 

 {literal}
<script type="application/ld+json">{$ldelim}
            {
              "@context": "http://schema.org",
              "@type": "Organization",
              "name": "{$pagetitle}",
              "description": "{$desc}",
            }
  {$rdelim}      </script>
{/literal}

 

Edited by Prahost
Link to comment
Share on other sites

10 minutes ago, Prahost said:

Non of them are working, my following code print as it is

 


 {literal}
<script type="application/ld+json">{$ldelim}
            {
              "@context": "http://schema.org",
              "@type": "Organization",
              "name": "{$pagetitle}",
              "description": "{$desc}",
            }
  {$rdelim}      </script>
{/literal}

 

try this:

<script type="application/ld+json">
{ldelim}
"@context": "http://schema.org",
"@type": "Organization",
"name": "{$pagetitle}",
"description": "{$desc}",
{rdelim}
</script>

 

Link to comment
Share on other sites

2 hours ago, WHMCS Andrew said:

The issue here is smarty's intelligent recognition that you are running javascript.

Try replacing your { in the first line with {$ldelim} - see https://www.smarty.net/docs/en/language.function.ldelim.tpl#idp36077424 for the full Smarty documentation


<script type="application/ld+json"> {$ldelim} 
"@context" : "http://schema.org",
"@type" : "Organization",
"name":"{$title}",
"description": "{$desc}",
  
  
....
{$rdelim}

 

it's {ldelim} and {rdelim}

Link to comment
Share on other sites

following code working fine If i remove {literal}.

As per my understanding all java scripts need to be in {literal} tag correct..? there is any way to use smarty without {ldelim) ?

<script type="application/ld+json">
{ldelim}
"@context": "http://schema.org",
"@type": "Organization",
"name": "{$pagetitle}",
"description": "{$desc}",
{rdelim}
</script>

 

Link to comment
Share on other sites

Just now, Prahost said:

following code working fine If i remove {literal}.

As per my understanding all java scripts need to be in {literal} tag correct..? there is any way to use smarty without {ldelim) ?


<script type="application/ld+json">
{ldelim}
"@context": "http://schema.org",
"@type": "Organization",
"name": "{$pagetitle}",
"description": "{$desc}",
{rdelim}
</script>

 

when you use {literal} it will ignore all the code in between, so {$pagetitle} will be displayed as it and will not be replaced with it's value.

on the other hand {ldelim} and {rdelim} work the same as {literal} but gives you the option to put some variables that you need to include in your CSS/JS codes, below is how this can be done using {literal}

{literal}
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Organization",
"name": "{/literal}{$pagetitle}{literal}",
"description": "{/literal}{$desc}{literal}",
}
</script>
{/literal}

 

Link to comment
Share on other sites

1 minute ago, sentq said:

when you use {literal} it will ignore all the code in between, so {$pagetitle} will be displayed as it and will not be replaced with it's value.

on the other hand {ldelim} and {rdelim} work the same as {literal} but gives you the option to put some variables that you need to include in your CSS/JS codes, below is how this can be done using {literal}


{literal}
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Organization",
"name": "{/literal}{$pagetitle}{literal}",
"description": "{/literal}{$desc}{literal}",
}
</script>
{/literal}

 

So there is no difference / affect on code, we can use either?

Link to comment
Share on other sites

  • WHMCS Developer
11 minutes ago, sentq said:

it's {ldelim} and {rdelim}

It is indeed.

 

2 minutes ago, Prahost said:

So there is no difference / affect on code, we can use either?

Exactly.

Although, in theory, you shouldn't actually need any literal tags at all as with Smarty V3, smarty will intelligently recognise the javascript part.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated