Forums / Developer / ezxmltext override with changes

ezxmltext override with changes

Author Message

Håkan Bergman

Monday 03 May 2010 5:37:53 am

Hello,

I got an article where user adds PDF-documents in the body text through links in the editor and are using the eznode://<nodeid> feature. The link however is not linking to the object in question but to another url where ezbinary.tpl is loaded with a proper download link.

I thought that I could easily change in link.tpl where I could just make a switch case to match type file and create a different a href to match content/download but I don't really understand how link.tpl is called, from where and where the data comes from.

Can anyone explain how I could do this in my link.tpl override for ezxmltext?

Best regards,

Håkan

Robin Muilwijk

Monday 03 May 2010 12:01:55 pm

Hi Håkan,

I might not have a solution for you but something similar crossed my path some time ago. This topic was related to getting a direct link to a file (download) to work. See http://share.ez.no/forums/setup-design/direct-link-to-a-file-on-image#comment56455, maybe the code and/or method used can help you.

Regards Robin

Board member, eZ Publish Community Project Board - Member of the share.ez.no team - Key values: Openness and Innovation.

LinkedIn: http://nl.linkedin.com/in/robinmuilwijk // Twitter: http://twitter.com/i_robin // Skype: robin.muilwijk

Håkan Bergman

Tuesday 04 May 2010 12:31:50 am

Hello Robin,

Thanks a lot for that link, I have now solved my problem!

The original code only printed the {$content} of every single URL but with that code I managed to tweak it.
This is content/datatype/ezxmltags/link.tpl file (overriden in my own extension)

{* Begin Code *}

---------------------------------------------------------------------------------------------------------------------------------------------------------

{* Define values we are checking for: type, content, attributes and URL *}

{def $protocols=array('http', 'file', 'ftp', 'mailto', 'https')
$mycontent = ""
$attribute = ""
$url = false()
}

{* Fetch content from path *}
{set $mycontent=fetch(content, node, hash(node_path, $href))}
{* Verify the path URL and identify the source *}
{switch match=$href}

{* If the path is a file object, print the direct URL to file for download *}
{case match=$mycontent.object.class_identifier|eq('file'))}
{set $attribute=$mycontent.data_map.file}
{set $url=concat( '/content/download/', $attribute.contentobject_id, '/', $attribute.id,'/version/', $attribute.version , '/file/', $attribute.content.original_filename|urlencode )}
<a href={$url|ezurl} target="_blank">{$attribute.object.name}</a>
{/case}

{* If no match was made, print the default URL link *}
{case}
<a href={$href|ezurl}
{if $id} id="{$id}"{/if}
{if $title} title="{$title}"{/if}
{if $target} target="{$target}"{/if}
{if $classification} class="{$classification|wash}"{/if}
{if and(is_set( $hreflang ), $hreflang)} hreflang="{$hreflang|wash}"{/if} >
{$content}
</a>
{/case}
{/switch}

---------------------------------------------------------------------------------------------------------------------------------------------------------
{* End Code *}