Publisher does not support the Fluid field type. Please do not contact asking when support will be available.

If you purchased an add-on from expressionengine.com, be sure to visit boldminded.com/claim to add the license to your account here on boldminded.com.

Ticket: Way to output translated URL

Status Resolved
Add-on / Version Publisher
Severity Trivial
EE Version

Wouter Vervloet

Mar 31, 2013

Hi Brian,

I needed a way to hardcode a few URL’s in the template (certain elements that link deeper into the site) so I made a little addition to Publisher to do this. As the path tag isn’t translated outside a channel:entries loop I did it this way:

/**
     * Tag to translate URL's based on entry_id
     *
     * {exp:publisher:url entry_id="{entry_id}"}
     * 
     * @return string
     */
    public function url()
    {
      $entry_id = $this->EE->TMPL->fetch_param('entry_id');

      $site_pages = $this->EE->config->item('site_pages');
      $site_uris = $site_pages[$this->EE->config->item('site_id')]['uris'];
      
      if (isset($site_uris[$entry_id]))
      {
          return $this->EE->functions->create_url($site_uris[$entry_id]);
      }

      return '';
    }

It’s pretty straight forward as most of the heavy lifting has already been done by the publisher extension (swapping out the page_urls with the translated ones).

– Wouter

 

#1

BoldMinded (Brian)

Does the new {page_uri:XX} variable not work for you in this case?

#2

Wouter Vervloet

It does work, but I came up with this solution before you made the fix. 😉

I did however add one other thing… it might be just me, but I like to have all my URL’s with the full path, not just the uri. So I added {page_url:XX} variables as well. These output the full URL to the page (like structure does).

– Wouter

#3

BoldMinded (Brian)

Well, the page_uri var can be used as a start_from parameter, the full URL won’t (or shouldn’t) work with Structure’s start_from param. Also, Wyvern creates the page_url:XX variables already, if you use that. I can add page_url:XX to the official release though.

#4

Brian Litzinger

0.98.5 will include both {page_url:XX} and {page_uri:XX} variables.

Login to reply