Jump to content

Getting Cms Page Url


bewater

Recommended Posts

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!

  • Like 1
Link to comment
Share on other sites

  • 1 year later...

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

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

  • 2 months later...

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

  • 2 years later...

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)}

  • Like 1
Link to comment
Share on other sites

  • 1 year later...
  • 11 months later...

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...