Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-08-11 11:20:49

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,172
Website GitHub Mastodon Twitter

Generic linking to sections categories and articles

I’ve recently discovered the joys of the permlink tag, especially when used in combination with other fields. ie. <txp:permlink id='<txp:image_info type="name">'><txp:thumbnail /><txp:permlink>

This method of linking images can work in a local environment before anything is uploaded. What happens though if some of the links need to point to a section or category? I understand that semantically permlinks should point to individual pages but the tag can also be used in the general design of a site and could be expanded as a generic one to cross link any page of a site.

Is this possible or hard? does anybody else wish that this functionality was included? Is there a pony in the area?

> Edit: changed title of post for clarity

Last edited by colak (2012-08-13 07:25:07)


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#2 2012-08-11 12:19:16

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Generic linking to sections categories and articles

There are specialized tags for generating links to categories and sections, including section and category tags respectfully. Both which follow the same syntax used by the permlink tag, supporting both a container and a single-tag use.

From what you writing and from the mentioned snippet, it seems that you want a multipurpose id attribute that can generate a link to any given content. This particularly doesn’t make much sense. First and the foremost, having a permlink tag to generate links to something else than an article doesn’t make much sense, since the tag is subject to contexts, just as the section and the category tags are.

Then there are the technical issues. If the id doesn’t use unique values, there are going to be collisions. It’s hard to know what the values should be. When it comes to handling the content, categories, section and articles all are different and have different features. For instance categories have types.

Now. If you do really just want a automatic link generation, which takes a single value, you can do it with the existing tags. We have variables and the three mentioned tags. Output_forms and the yield can be used to host and create snippets.

For instance with a form partial that contains something along the lines of the following:

<txp:variable name="page_url"><txp:permlink id='<txp:variable name="page:id" />' /></txp:variable>

<txp:category_list categories='<txp:variable name="page:id" />'>
	<txp:variable name="page_url"><txp:category url="1" /></txp:variable>
</txp:category_list>

<txp:section_list sections='<txp:variable name="page:id" />'>
	<txp:variable name="page_url"><txp:section url="1" /></txp:variable>
</txp:section_list>

<txp:if_variable name="page_url" value="">
	<txp:yield />
<txp:else />
	<a href="<txp:variable name="page_url" />"><txp:yield /></a>
</txp:if_variable>

You would be able to create a link to a category, a section or an article with the same tag and the same attribute. For example:

<txp:variable name="page:id" value="home" />
<txp:output_form form="page">
	Link text or <strong>markup</strong> here.
</txp:output_form>

Where in the above the page is the name of the form hosting the code and the page:id variable is the linked page. It can take either an article ID, a category or a section as its value.

Offline

#3 2012-08-11 15:47:17

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,172
Website GitHub Mastodon Twitter

Re: Generic linking to sections categories and articles

This is absolute coolness. Off to test it now!


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#4 2012-08-12 04:57:39

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,172
Website GitHub Mastodon Twitter

Re: Generic linking to sections categories and articles

As it seems that my feature request is possible using existing tags, I moved this thread to the appropriate forum

Jukka, thanks sooo much for your advice.

After testing it a few times i don’t seem to be able to understand how it works so as to make it function properly:(

In its bare bones, what I am trying to achieve is

<txp:images>
<a href="<txp:image_info type="name" />"><txp:image /></a>
</txp:images>

where <txp:image_info type="name" /> would accept article ids, sections and optionally, categories so that the image would be linked to that article, section or category. I know that I could just use <txp:site_url /><txp:image_info type="name" /> and type the remaining url in <txp:image_info type="name" /> but this method will make updating the site a nightmare should I, or somebody else, ever decide to change the url schema.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#5 2012-08-13 07:35:22

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,172
Website GitHub Mastodon Twitter

Re: Generic linking to sections categories and articles

so many views, so few replies :/


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#6 2012-08-13 12:57:05

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,172
Website GitHub Mastodon Twitter

Re: Generic linking to sections categories and articles

I was thinking that one way to solve this is set a variable which could detect if the contents of the <txp:image_info type="name" /> field is numeric or not.

From an example I found on the net this is I would like to achieve

<?php 
 if (is_numeric (<txp:image_info type="name" />)) 
 {
 echo "<a href="<txp:permlink id='<txp:image_info type="name" />"><txp:image /></a>'>";
 } else {
 echo "<a href="<txp:site_url /><txp:image_info type="name" />"><txp:image /></a>";
 }
 ?>

can anyone advice me on how i can adapt the code above for txp?


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#7 2012-08-15 16:02:27

etc
Developer
Registered: 2010-11-11
Posts: 5,397
Website GitHub

Re: Generic linking to sections categories and articles

I’m a little lost in what you want to achieve, but the following should import the code above into txp:

<txp:etc_query data='<txp:image_info type="name" />'>
{$is_numeric.?(
<a href='<txp:permlink id="{?}"'><txp:image /></a>|
<a href='<txp:site_url />{?}'><txp:image /></a>
)}
</txp:etc_query>

Offline

#8 2012-08-15 16:24:28

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,172
Website GitHub Mastodon Twitter

Re: Generic linking to sections categories and articles

thanks Oleg,

i’ll check it out


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

Board footer

Powered by FluxBB