bewater Posted February 26, 2013 Share Posted February 26, 2013 HI, how get I get the right CMS page url? I need to create a menu that links to them so I have to write the url correctly, avoiding problem like translations or friendly url. Tks G. Link to comment Share on other sites More sharing options...
NemoPS Posted February 26, 2013 Share Posted February 26, 2013 Hi there, It should be IN TEMPLATES $link->getCMSLink('pagenamehere') IN YOUR PHP $this->context->link->getCMSLink('nameheretoo') here is the reference function (link.php class) /** * Create a link to a CMS page * * @param mixed $cms CMS object (can be an ID CMS, but deprecated) * @param string $alias * @param bool $ssl * @param int $id_lang * @return string */ public function getCMSLink($cms, $alias = null, $ssl = false, $id_lang = null) { $base = (($ssl && $this->ssl_enable) ? _PS_BASE_URL_SSL_ : _PS_BASE_URL_); if (!$id_lang) $id_lang = Context::getContext()->language->id; $url = $base.__PS_BASE_URI__.$this->getLangLink($id_lang); if (!is_object($cms)) $cms = new CMS($cms, $id_lang); // Set available keywords $params = array(); $params['id'] = $cms->id; $params['rewrite'] = (!$alias) ? (is_array($cms->link_rewrite) ? $cms->link_rewrite[(int)$id_lang] : $cms->link_rewrite) : $alias; if (isset($cms->meta_keywords) && !empty($cms->meta_keywords)) $params['meta_keywords'] = is_array($cms->meta_keywords) ? Tools::str2url($cms->meta_keywords[(int)$id_lang]) : Tools::str2url($cms->meta_keywords); else $params['meta_keywords'] = ''; if (isset($cms->meta_title) && !empty($cms->meta_title)) $params['meta_title'] = is_array($cms->meta_title) ? Tools::str2url($cms->meta_title[(int)$id_lang]) : Tools::str2url($cms->meta_title); else $params['meta_title'] = ''; return $url.Dispatcher::getInstance()->createUrl('cms_rule', $id_lang, $params, $this->allow); } Cheers! 1 Link to comment Share on other sites More sharing options...
bewater Posted February 26, 2013 Author Share Posted February 26, 2013 Tks a lot. Another question: if I want to get the NAME (because it changes depending on the language) of the cms page, what function sholud I use? tks in advance Link to comment Share on other sites More sharing options...
NemoPS Posted February 26, 2013 Share Posted February 26, 2013 You can't without a database query, you'll have to hardcode it and make that translatable {l s='nameofthelink' mod='modulename'} Link to comment Share on other sites More sharing options...
Chima42 Posted February 15, 2015 Share Posted February 15, 2015 Hello, Where can i find "TEMPLATES"? I'm using 1.6 Link to comment Share on other sites More sharing options...
NemoPS Posted February 16, 2015 Share Posted February 16, 2015 uh...? What are you asking, exactly? Where to find prestashop templates, or where to find the template folder? Link to comment Share on other sites More sharing options...
Chima42 Posted February 16, 2015 Share Posted February 16, 2015 Sorry, let me be a little more descriptive of what i'm trying to do. I've successfully added a cms page to the navigation bar but i cannot link to it. Is the above code a way to do this? I also found this snippet online: <li><a href="{$link->getCMSLink('9', 'desktop')|escape:'html'}" title="{l s='new' mod='blockpermanentlinks'}">{l s='new' mod='blockpermanentlinks'}</a></li> but i'm not sure? Link to comment Share on other sites More sharing options...
NemoPS Posted February 16, 2015 Share Posted February 16, 2015 That should be correct as long as the friendly url of the page is desktop and the id is 9, of course Link to comment Share on other sites More sharing options...
Chima42 Posted February 16, 2015 Share Posted February 16, 2015 okay brilliant which it all is, but where do i paste this? Link to comment Share on other sites More sharing options...
NemoPS Posted February 16, 2015 Share Posted February 16, 2015 ah, you want it in the top menu? it depends if your theme has a template override theme folder /modules/blocktopmenu/blocktopmenu.tpl or /modules/blocktopmenu/blocktopmenu.tpl Link to comment Share on other sites More sharing options...
Chima42 Posted February 16, 2015 Share Posted February 16, 2015 Inside that folder this i only have and index file. with this inside: {if $MENU != ''} <!-- Menu --> <div id="block_top_menu" class="sf-contener clearfix col-lg-12"> <div class="cat-title">{l s="Categories" mod="blocktopmenu"}</div> <ul class="sf-menu clearfix menu-content"> {$MENU} {if $MENU_SEARCH} <li class="sf-search noBack" style="float:right"> <form id="searchbox" action="{$link->getPageLink('search')|escape:'html':'UTF-8'}" method="get"> <p> <input type="hidden" name="controller" value="search" /> <input type="hidden" value="position" name="orderby"/> <input type="hidden" value="desc" name="orderway"/> <input type="text" name="search_query" value="{if isset($smarty.get.search_query)}{$smarty.get.search_query|escape:'html':'UTF-8'}{/if}" /> </p> </form> </li> {/if} </ul> </div> <!--/ Menu --> {/if} also i'm editing default-bootstrap template because i don't know how to create another one? IS this advised? Link to comment Share on other sites More sharing options...
NemoPS Posted February 18, 2015 Share Posted February 18, 2015 Yes, that's it, just add another <li> after the {/if}, or before the opening if; depends on where you want the new element Link to comment Share on other sites More sharing options...
Chima42 Posted February 18, 2015 Share Posted February 18, 2015 Hello, thank you for your help so far. I've added that and it's not come up, how do i know whetehr or not i have a template override? Link to comment Share on other sites More sharing options...
Chima42 Posted February 19, 2015 Share Posted February 19, 2015 Hello, I've managed this now! My site was caching from the setting in the Back Office! Link to comment Share on other sites More sharing options...
st0le Posted April 25, 2015 Share Posted April 25, 2015 WOW! I have the same problem, I need the URL... in 1.5 you only should click to view and take the URLIs necessary all of this? Cheers Link to comment Share on other sites More sharing options...
NemoPS Posted April 27, 2015 Share Posted April 27, 2015 If you know both the id and friendly url, you can use this, as explained above <li><a href="{$link->getCMSLink('9', 'desktop')|escape:'html'}" title="{l s='new' mod='blockpermanentlinks'}">{l s='new' mod='blockpermanentlinks'}</a></li> Link to comment Share on other sites More sharing options...
misthero Posted June 26, 2017 Share Posted June 26, 2017 If you know both the id and friendly url, you can use this, as explained above <li><a href="{$link->getCMSLink('9', 'desktop')|escape:'html'}" title="{l s='new' mod='blockpermanentlinks'}">{l s='new' mod='blockpermanentlinks'}</a></li> I think it works with the ID only : {$link->getCMSLink(9)} 1 Link to comment Share on other sites More sharing options...
Julien Posted June 28, 2018 Share Posted June 28, 2018 (edited) Thanks Edited June 28, 2018 by Julien (see edit history) Link to comment Share on other sites More sharing options...
PF22 Posted June 13, 2019 Share Posted June 13, 2019 Hi there. I have a problem to use CMS page url. Actually I want customer to get to authentification before getting access to a specific CMS page. I tried the code below in cms.tpl, but after authentification I get back to home page... {Tools::redirect('index.php?controller=authentication?back=$link->getCMSLink(9)')} Any idea ? Thanks. Link to comment Share on other sites More sharing options...
NemoPS Posted June 13, 2019 Share Posted June 13, 2019 Is the value of "back" in the url after you click? Link to comment Share on other sites More sharing options...
PF22 Posted June 13, 2019 Share Posted June 13, 2019 Thanks @NemoPS. When I am on the authentification page, the url is https://www.mywebsite.org/authentification?back=https://www.mywebsite.org/content/29-my-page Link to comment Share on other sites More sharing options...
PF22 Posted June 20, 2019 Share Posted June 20, 2019 UP I can't find what to set in the back Value to reach back to https://www.mywebsite.org/content/29-my-page once the user has been authentificated... Thanks ! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now