Search code examples
phpsmartyimagesrc

Smarty's template inheritence and img src attribut


Is there a way to make Smarty convert src & href attributs values to the correct URL when using template inheritence

exmple:

file: web/tpl/layout.tpl

<img src="../img/logo.png" />
{block name=content}{/block}

file: index.tpl

{extends file="web/tpl/layout"}
{block name=content} home page content here{/block}

file: dir/index.tpl

{extends file="../web/tpl/layout"}
{block name=content} an other page content here{/block}

Solution

  • I think you should define your base url and use that in your src and href:

    <img src="{$baseurl}/img/logo.png" />
    {block name=content}{/block}