How to link an URL inside the them from the Diazo rules file?

大兔子大兔子 提交于 2019-12-13 02:15:39

问题


If an URL to a image is set in a HTML template, then the URL is updated to reference files inside the theme folder. For example,

<img src="image.png" />

is replaced by:

<img src="http://localhost:8080/mysite/++theme++mytheme-theme/image.png" />

However, if I write following Diazo rule:

<replace css:content="#some-class">
   <div id="#some-class"><img src="image.png" /></div>
</replace>

the URL of the image is not update. How can I write Diazo rules where the image gets correctly referred. I want to refer this image in the template HTML file with <img src="path/image.png">. However it is not clear what to put instead of path. I notice that path cannot be an absolute path because it depends of the site domain. Also, it cannot be a relative path because it depends on the path of each page in the site. May be it would be useful to have an specific keyword to reference the theme folder. For example, <img src="$themeFolder/image.png">. Exists such keyword?


回答1:


You may create XSLT parameters in your theme's manifest.cfg file. Just add a stanza like:

[theme:parameters]
theme_base_url = string:${portal_state/portal_url}/++theme++mytheme-theme/

Then you may use it in your rules file:

<replace css:content="#some-class">
   <div id="#some-class">
     <img><xsl:attribute name="src"><xsl:value-of select='$theme_base_url' />image.png</xsl:attribute></img>
  </div>
</replace>


来源:https://stackoverflow.com/questions/31633395/how-to-link-an-url-inside-the-them-from-the-diazo-rules-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!