Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2019-12-12 09:38:10

Myusername
Member
Registered: 2019-12-12
Posts: 73

help for a site_url and page_url tag

I did not find in the documentation any tags that could return me the url of the page, be it homepage or post page. So my solution was to use <txp:site_url/><txp:page_url/>.

It turns out that the first tag returns the homepage url with a slash at the end, and the other tag returns starting with a slash as well. So it looks like: (https: //example.com//articles/…).

I tried to remove the slash using php, but it seems that the site_url() and page_url() functions don’t work inside a txp:php tag. I would also like to know why.

could someone help me with this?

Last edited by Myusername (2019-12-12 10:03:50)

Offline

#2 2019-12-12 09:45:45

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,293
Website

Re: help for a site_url and page_url tag

Hi and welcome to txp. For individual articles <txp:permlink /> should help.


Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github | Covid-19; a resource
I do my best editing after I click on the submit button.

Offline

#3 2019-12-12 09:51:54

Myusername
Member
Registered: 2019-12-12
Posts: 73

Re: help for a site_url and page_url tag

colak wrote #320482:

Hi and welcome to txp. For individual articles <txp:permlink /> should help.

yes, but that doesn’t work on category pages, for example

Offline

#4 2019-12-12 10:01:11

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 8,293
Website

Re: help for a site_url and page_url tag

Myusername wrote #320483:

yes, but that doesn’t work on category pages, for example

Indeed. and that is why we can use conditionals. Here is an untested hopefully working solution

<txp:if_individual_article>
<txp:permlink />
<txp:else />
http(s)://www.domain.tld<txp:page_url />
</txp:if_individual_article>

Yiannis
——————————
neme.org | hblack.net | LABS | State Machines | NeMe @ github | Covid-19; a resource
I do my best editing after I click on the submit button.

Offline

#5 2019-12-12 10:14:52

Myusername
Member
Registered: 2019-12-12
Posts: 73

Re: help for a site_url and page_url tag

colak wrote #320484:

Indeed. and that is why we can use conditionals. Here is an untested hopefully working solution

<txp:if_individual_article>...

I thought about doing this, but the url I am currently using is just for testing, so I will later have to manually change this when I change to my original domain.

Anyway, thanks for the help.

One more thing if I can clarify, functions like body(), excerpt() and many others can be handled within <txt:php>, but that doesn’t happen with site_url() or page_url(), right? Why?

I’m still new to php.

Last edited by Myusername (2019-12-12 10:15:41)

Offline

#6 2019-12-12 11:31:40

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,786
Website

Re: help for a site_url and page_url tag

The <txp:site_url /> and <txp:page_url /> tags are not normally used together. If constructing links to other pages, you don’t need <txp:site_url /> since the <txp:page_url /> tag returns root-relative paths that the browser automatically prefixes with the domain.

You can build complete links if you like from the various components such as <txp:section /> and <txp:article_url_title />, utilising conditional tags to determine which type of page you’re on.

May we ask why you need the full canonical path to the page? Might be something we can help with, or build into core in the next version (e.g. another type option to <txp:page_url> that returns the full page path including domain).

EDIT: but since, as Oleg points out, we have the trim attribute, we’re pretty much covered already.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#7 2019-12-12 11:33:30

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,786
Website

Re: help for a site_url and page_url tag

Oh, and in answer to your question about PHP, you can use any registered tag by enclosing it in parse(). e.g. :

<txp:php>echo parse('<txp:site_url />');</txp:php>

The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#8 2019-12-12 11:43:27

etc
Developer
Registered: 2010-11-11
Posts: 3,940
Website

Re: help for a site_url and page_url tag

To remove the trailing slash:

<txp:site_url trim="/" />

Offline

#9 2019-12-12 17:21:37

Myusername
Member
Registered: 2019-12-12
Posts: 73

Re: help for a site_url and page_url tag

Bloke wrote #320486:

May we ask why you need the full canonical path to the page? Might be something we can help with, or build into core in the next version (e.g. another type option to <txp:page_url> that returns the full page path including domain).

I need to put the page url in some head tags. Like this one below, for example:

<link rel = “canonical” href = “…” />

Therefore, I need the full URL, but the “Trim” must be resolved.

Bloke wrote #320487:

Oh, and in answer to your question about PHP, you can use any registered tag by enclosing it in parse(). e.g. :

<txp:php>echo parse('<txp:site_url />');</txp:php>...

Thanks for the reply, it will definitely help me a lot!

Last edited by Myusername (2019-12-12 17:23:06)

Offline

#10 2019-12-12 17:24:37

Myusername
Member
Registered: 2019-12-12
Posts: 73

Re: help for a site_url and page_url tag

etc wrote #320488:

To remove the trailing slash:

<txp:site_url trim="/" />...

Did not know about the attribute “trim” will certainly be useful. Thank you.

Offline

Board footer

Powered by FluxBB