Forums / Setup & design / open link in a new window? help needed

open link in a new window? help needed

Author Message

Albert Berenguer

Monday 19 May 2003 8:07:06 am

Hi!
I need some help with Link datatype (URL). I have a folder with a list of links (class id number 25) wich I want to be opened in new windows. When viewing them "line_class_25.tpl" is used, and the HTML link (< a href="... >text< /a>) is created with the code:

{ attribute_view_gui attribute=$content_version.data_map.link }

To open the link in a new window some HTML (target=_blank) or JavaScript code should be written inside the < a> tag but, as it is created dinamically with the template code I don't see the way to do it.
I also tried to access directly the attribute which has the URL in the Link object (and then write the HTML code directly in line_class_25.tpl) but didn't find the way to. I didn't know what was the object structure and the attribute names.

I hope I explained my problem clearly enough, thanks in advance for all the help provided.

Berto

Albert Berenguer

Tuesday 20 May 2003 7:36:19 am

the solution was to modify "/design/standard/templates/content/datatype/view/ezurl.tpl"

greetings from a newbie :P

berto

J W

Friday 10 October 2003 3:31:34 am

Sorry i kick this topic, but this is exactly the problem i'm having now!

I saw and tested your solution and it works, but this is not the perfect sollution.

The perfect sollution would be if you could choose per link if it needs to be opened in a new browser or not.

For example:
In the standard class "article" i added the datatype "url" (just to test). The best way should be if you've got here an option for it. Just an checkbox if it needs to open a new window.

Is this possible to do this? I must say i'm a newbie with ezPublish.

Alex Jones

Friday 10 October 2003 6:15:22 am

J W, here are some ideas that I have cobbled together from some of my templates. You may have to tweak them a bit to get it to work.

1. Add a checkbox to your class - For this example I am going to call it 'New Window?' and assign it the identifier 'newwindow'.

2. Add a section block that checks the checkbox to your code:
{section show=eq($content_version.data_map.newwindow.content,'')}
{* Displayed if the "New Window" box is not checked *}
{section-else}
{* Displayed if the "New Window" box is checked *}
{/section}

3. Within the second section in the above code insert your code to display a link that opens in a new window. Set the first section to display it normally.

4. Here is part of the code I use in an image override templateto open an image in a JavaScript window (the actual JavaScript is included in a different part of the window):
<a href={$image_content[original].full_path|ezroot} target="_soopaPop:width={$image_content[original].width},height={$image_content[original].height},screenX=50,screenY=50,resizable"><img src={$image.full_path|ezroot} width="{$image.width}" height="{$image.height}" {section show=$hspace}hspace="{$hspace}"{/section} {section show=$alignment}align="{$alignment}"{/section} border="{$border_size}" alt="{$image_content.alternative_text|wash(xhtml)}" /></a>
{/let}

Hope this helps. Let me know if something doesn't make sense.

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

J W

Monday 13 October 2003 2:17:54 am

Alex, thanks for your answer.

It does make sense and your sollution works.

But it isn't exactly the thing i want. The best sollution is, in my opinion, that when you create an class, and you add an datatype "URL", that you can choose there the target of the link.

I think this is one thing that is not possible (yet). So i'm going to use your sollution.

Thanx.

Alex Jones

Monday 13 October 2003 6:47:43 am

Ahhh, I think I see what you would like. Perhaps for now you could add an extra text line to your link/URL class where you can fill in the target. Then edit the code in an override template for ezurl.tpl to include
target="{path.to.your.textline}"

Would this do what you want?

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

J W

Monday 13 October 2003 7:29:04 am

Yes, that will work, i think.

The only problem is that i don't know how to add the "link/URL class" so we can fill in the target.

I hope someone could explain that to me.
I'm really a newbie with ezPublish and i'm trying to understand how everything works, that's why i don't know how to do this on myself.

Alex Jones

Monday 13 October 2003 7:49:18 am

Do you mean you do not know how to edit the class or how to modify the code that the code outputs?

To edit the class go to your admin area and click on the 'Set up' tab and view the Classes. Click on the Edit link next to the Link datatype (mine is set up as number 11). Scroll down to the bottom of the box where it says Datatype and choose the 'Text line' from the drop down box and click on 'New'. The page will reload and provide you with some fields to fill out. For this example put 'Target' in the Name field and 'target' in the Identifier field. You could also do this with the Enum operator if you want to force the editor to select from a list.

Now when you add a link to eZ publish you will see the Target field, which you can fill in with the value you want for the target (_blank for example).

To output your code you will want to create an override for the ezurl.tpl file. Copy the file ezurl.tpl from design/standard/templates/content/datatype/view/

Place it in your override design directory and modify the code so it provide the target. An example might be:
{default node_name=$node.name}
<a href={concat('/',$node.url_alias)|ezroot} target="$node.data_map.target.content">{$node_name|wash}</a>
{/default}

Use something along these lines in your override.ini.append:

[url_with_target]
Source=node/view/line.tpl
MatchFile=url_with_target.tpl
Subdir=templates
Match[class]=25

Note: The above code may require some changes to work with your set up. I wrote this off the top of my head - I haven't tested it. It may have mistakes in it.

Does this help?

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>