Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

trying to Add dynamic canonical tags

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
jongos
Smarty n00b


Joined: 26 Mar 2022
Posts: 2

PostPosted: Sat Mar 26, 2022 8:00 am    Post subject: trying to Add dynamic canonical tags Reply with quote

Hello

im trying add dynamic hardcode canonical tags within my head tags like this one ( cross domain canonical tags)

Code:
<link rel='canonical' href="https://www.domainname.com<?=$_SERVER['REQUEST_URI']?>" >


Code:
https://stackoverflow.com/questions/21300474/create-a-canonical-url-with-php



the code works fine in a regular PHP site but it's not working in smarty templating site (open journals system OJS)

the header.tpl is something like this

Code:
{**
 * templates/frontend/components/headerHead.tpl
 *
 * Copyright (c) 2014-2021 Simon Fraser University
 * Copyright (c) 2000-2021 John Willinsky
 * Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
 *
 * Common site header <head> tag and contents.
 *}
<head>
   <meta charset="{$defaultCharset|escape}">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>
      {$pageTitleTranslated|strip_tags}
      {* Add the journal name to the end of page titles *}
      {if $requestedPage|escape|default:"index" != 'index' && $currentContext && $currentContext->getLocalizedName()}
         | {$currentContext->getLocalizedName()}
      {/if}
   </title>

   {load_header context="frontend"}
   {load_stylesheet context="frontend"}
</head>


can someone help me
Back to top
View user's profile Send private message
bsmither
Smarty Elite


Joined: 20 Dec 2011
Posts: 322
Location: West Coast

PostPosted: Sat Mar 26, 2022 8:12 pm    Post subject: Reply with quote

You will want the Smarty equivalent:
Code:
<link rel='canonical' href="https://www.domainname.com{$smarty.server.REQUEST_URI}">

https://www.smarty.net/docs/en/language.variables.smarty.tpl#language.variables.smarty.request
Back to top
View user's profile Send private message
jongos
Smarty n00b


Joined: 26 Mar 2022
Posts: 2

PostPosted: Sun Mar 27, 2022 11:35 am    Post subject: Reply with quote

thank you very much bsmither, you're a life saver
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Wed Apr 06, 2022 11:17 am    Post subject: Reply with quote

Don't forget to escape the output value appropriately.
In both cases.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP