eZ Community » Forums » eZ Publish 5 Platform » Custom attribute for <link> tag with...
expandshrink

Custom attribute for <link> tag with image.tpl

Custom attribute for <link> tag with image.tpl

Monday 02 July 2018 5:25:01 pm - 2 replies

I have exactly the same problem as Don Ronaldo in his message: "Custom attribute for <link> tag with image.tpl"

http://share.ez.no/forums/setup-design/custom-attribute-for-link-tag-with-image.tpl

Except my variable $link_parameters doesn't exist...

eZ Publish version 4.0.1

Modified on Monday 02 July 2018 5:31:59 pm by Rémy PHP

Monday 02 July 2018 5:27:03 pm

extension/ebb/design/ebb/templates/content/datatype/view/ezxmltags/link.tpl

Works fine, as long as a link is applied to a string only.

 <a href="{$href|ezurl('no')}"
        {if is_set($onclick)}   onclick="{$onclick}"    {/if}
        {if is_set($rel)}       rel="{$rel}"            {/if}
        {if is_set($atinternet_name)}       data-atinternet_name="{$atinternet_name}"            {/if}
        {if is_set($atinternet_advertising)}       data-atinternet_advertising="{$atinternet_advertising}"            {/if}
        {section show=$id} id="{$id}"{/section}
        {section show=$title} title="{$title}"{/section}
        {section show=$target} target="{$target}"{/section}
        {section show=ne($classification|trim,'')} class="{$classification|wash}"{/section}
    >
    {$content}
</a>

 

However, when a <link> is applied to an image in xml content attribute, the <a> tag is rendered by image.tpl rather than by link.tpl.

extension/ebb/design/ebb/templates/content/datatype/view/ezimage.tpl

 {*
@param eZContentObjectAttribute $attribute
@param string $image_class
@param string $css_class
@param string $alignment
@param bool   $link_to_image    Est ce que l'image affichée doit être un lien vers l'image originale. Si oui: écrase le href passé en paramètre.
@param string $href             URL du lien !!! AVEC les boubles-côtes !!!!
@param string $target
@param string $link_class
@param string $link_id
@param string $hspace
@param string $border_size
@param bool   $map
@param string $legende
*}
 
{$link_parameters|attribute(show,1)}{* Unknown template variable 'link_parameters' in namespace 'xmltagns:ContentView:ContentAttribute' *}
 
{if ezini( 'SiteSettings', 'SiteURL' )|contains('http://')}
    {def $site_url=ezini( 'SiteSettings', 'SiteURL')}
{else}
    {def $site_url=concat('http://', ezini( 'SiteSettings', 'SiteURL' ))}
{/if}
{default image_class=large
         css_class=false()
         alignment=false()
         link_to_image=false()
         href=false()
         target=false()
         hspace=false()
         border_size=0
         map=false()}
 
{let image_content=$attribute.content}
 
{section show=$image_content.is_valid}
 
    {let image=$image_content[$image_class]}
 
    {section show=$link_to_image}
        {let image_original=$image_content['original']}
        {set href=$image_original.url|ezroot}
        {/let}
    {/section}
    {switch match=$alignment}
    {case match='left'}
        <div class="imageleft">
    {/case}
    {case match='right'}
        <div class="imageright">
    {/case}
    {case/}
    {/switch}
 
    {section show=$css_class}
        <div class="{$css_class|wash}">
    {/section}
    
    {def $texte_alternatif = ''}
    {if is_set($image.text)}
        {set $texte_alternatif = $image.text|strip_tags()|xmlwash()}
    {/if}
    {if is_set($legende)}
        {set $texte_alternatif = $legende|strip_tags()|xmlwash()}
    {/if}
 
    {section show=and( is_set( $image ), $image )}
        {section show=$href}
            <a href={$href}
                    {section show=and( is_set( $link_class ), $link_class )} class="{$link_class}"{/section}
                    {section show=and( is_set( $link_id ), $link_id )} id="{$link_id}"{/section}
                    {section show=$target} target="{$target}"{/section}
                >
        {/section}
        <img src="{concat($site_url,$image.url|ezroot(no))}" width="{$image.width}" height="{$image.height}"
             {section show=$hspace}hspace="{$hspace}"{/section}
                style="border: {$border_size}px;" alt="{$texte_alternatif}" title="{$texte_alternatif}"
                {if $map} usemap="#map"{/if}
            />
        {section show=$href}
            </a>
        {/section}
    {/section}
 
    {section show=$css_class}
        </div>
    {/section}
 
    {switch match=$alignment}
    {case match='left'}
        </div>
    {/case}
    {case match='right'}
        </div>
    {/case}
    {case/}
    {/switch}
 
    {/let}
 
{/section}
 
{/let}
 
{/default}

Modified on Monday 02 July 2018 5:31:08 pm by Rémy PHP

Monday 02 July 2018 5:49:48 pm

Got it !!!

extension/ebb/design/ebb/override/templates/embed/image.tpl

  {attribute_view_gui attribute=$object.data_map.image image_class=$object_parameters.size href=$link_parameters.href|ezurl target=$link_parameters.target}

Just add

  link_parameters=$link_parameters
expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from