Forums / Setup & design / How to create a link from one article to another in ez publish 3

How to create a link from one article to another in ez publish 3

Author Message

Geir Pedersen

Monday 29 September 2003 3:15:13 am

Can anyone enlighten me as to how I can link from one article to another using ezpublish 3?

Inserting <link id='xxx'> seems to work in a very limited way. I am able to create links to some articles this way, but not to the majority. Also, it seems that sometimes ezpublish will have rewritten a link-element to an a-element when I open an article for further editing.

Is link the right element to use? What attributes are available and how do I specify the article or object I want to link to? Should I modify any configuration files to make this work?

I was sort of expecting that I could use the related object feature to find articles or objects I want to link to and then insert links into the article using a shorthand notation.

Vivienne van Velzen

Monday 29 September 2003 11:18:16 pm

Hi Geir,

You can use object relations to link from one article to another. After you created the object relation, you have to paste the example code into the article you want to link from. The example code is something like: <object id='1594' /> (this is shown under the related object in the editscreen).
Inserting this code will cause a link to appear in the article.
Example:
1. I want to link from article 1 to article 2 (title "I'm linked" ).
2. I create a object relation to article 2 (<object id='1' /> ) in the edit screen of article 1.
3. I then add the following description to article 1:
I'm linking to article 2 from here: <object id='1' />.
4. After publishing article 1, the visitor will see the following text under article 1:
I'm linking to article 2 from here: I'm linked.
(where the link is under "I'm linked" ).

Hope this helps,

Vivienne

Geir Pedersen

Wednesday 01 October 2003 1:02:01 pm

Vivienne,

Thanks for explaining the object-element. Based on your post I understand this is the main method for including links to other on-site articles and objects.

However, when I use this method on the intranet sample site, links are not shown inline in the current paragraph, but shown as block elements. Also, I can't find a way to set the source anchor text, i.e. the text you click on. (I understand this is taken from the object you link to.)

What I am looking for is a way to generate a hypertext link from one article to another article. The link should be displayed as an inline element, and I should be able to control both the anchor text as well as the title-attribute of the anchor element.

Since writing my initial message, I've done a dive into the ez publish 3.2 code to find a way to achieve my goal. I learnt several things:

It is possible to have an object xml element displayed inline in the current paragraph. The file ./design/standard/templates/content/datatype/view/ezxmltags/object.tpl contains a hint on how to do this in the following comment from the file:

Set variable to true if the object should be rendered
as a block tag. If it should be rendered as inline use
false.
{set-block scope=root variable=is_block}true{/set-block}

I tried this, but it did not work.

I went further into the code and discovered that if I made a small change in kernel/classes/datatypes/ezxmltext/handlers/output/ezxhtmlxmloutput.php the is_block variable from above took effect.

What I did was to change this line:

if ( $tpl->hasVariable( 'is_block', 'xmltagns:ContentView' ) )

into this:

if ( $tpl->hasVariable( 'is_block', 'xmltagns' ) )

The change has to do with what namespace hasVariable() checks for presence of is_block. I'm unable to tell if this is a simple typo, or what the full story is here.

After making the change above, I am now able to control via templates if object-elements are displayed inline in the current paragraph or as a separate block-level element.

The next thing I would like to see is a way to control both the anchor text and the title attribute of the html a-element. As far as I can see the ez publish xml object element does not support a title-attribute, but I could be wrong on that. What I would like to see is that the object-element supports two attributes, title and text. The text-attribute can be used to hold what will become the anchor text of the html a-element.

I would love to hear comments from people who really know the ezxmltext code and what the plans are for further development of this module.