eZ Community » Forums » eZ Publish 5 Platform » XML to HTML



Friday 08 August 2014 2:03:25 pm - 5 replies

I have a text in xml block which is render as follow

<a name="eztoc1_1" id="eztoc1_1"></a><h2><strong>Bienvenue dans l'espace pro</strong><
/h2><a name="eztoc1_1_1_1" id="eztoc1_1_1_1">

"Bienvenue dans l'esapce pro" is text wich is define as Title1 in my BO.

So I would like to replace h2 with h1 and remove other balise.

I did a specific template for my ez_render_field.

Now how should I chage the converter ? Create a txig extension to replace the xml_to_html5 ??

Tahnks for your help.

Saturday 09 August 2014 6:56:57 pm

You can configure this in a custom tag XSL file. See this documentation on how to add your own file on top of the default: https://doc.ez.no/display/EZP/How+to+implement+a+Custom+Tag+for+XMLText+FieldType

Then in your custom tag XSL file you can add a block such as this. That will do an exact match of header levels. You can modify the rest of the tags as desired.

     <xsl:template match="header">
        <!-- Make header levels match exactly instead of 1 level lower -->
        <xsl:variable name="level" select="count(ancestor-or-self::section)"/>
        <xsl:variable name="name">
            <xsl:number count="section" level="multiple"/>
        <a name="eztoc{translate($name, '.', '_')}" id="eztoc{translate($name, '.', '_')}"/>
        <xsl:element name="h{$level - 1}"><!-- Undo what eZ Publish does natively, which is to add to the header number -->
            <xsl:copy-of select="@class"/>
            <!-- custom classes(fields: ezoe_attributes.ini.append.php, attr: content.ini.append.php) -->
            <xsl:attribute name="class">
                <xsl:value-of select="@class"/>
                <!-- .center -->
                <xsl:if test="@custom:center != ''">
                    <xsl:text> center</xsl:text>
                <!-- .u-margin-reset -->
                <xsl:if test="@custom:u-margin-reset != ''">
                    <xsl:text> u-margin-reset</xsl:text>
                <!-- .u-inline-el -->
                <xsl:if test="@custom:u-inline-el != ''">
                    <xsl:text> u-inline-el</xsl:text>
            <xsl:copy-of select="@align"/>

Monday 11 August 2014 10:01:04 am

THANKS. It's very helpfull.

Just to understand what means those paramteters :


xmlns:xsl="http://www.w3.org/1999/XSL/Transform"        xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/"        xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/"        xmlns:image="http://ez.no/namespaces/ezpublish3/image/"        exclude-result-prefixes="xhtml custom image"


Is there any ezpublish documentation to understand xsl description ? :

 <span><span><xsl:variable</span> <span>name</span>=<span>"level"</span> <span>select</span>=<span>"count(ancestor-or-self::section)"</span><span>/></span></span>        <span><span><xsl:variable</span> <span>name</span>=<span>"name"</span><span>></span></span>            <span><span><xsl:number</span> <span>count</span>=<span>"section"</span> <span>level</span>=<span>"multiple"</span><span>/></span></span>        <span><span></xsl:variable></span></span>

Thanks for your help

Monday 11 August 2014 4:54:24 pm

I would like to remove <div class="ezxmltext-field">

If anyone has an idea.



Monday 11 August 2014 7:03:55 pm

If you want to remove the div you must create a new template for that type of field.

In this case I am creating the template in your bundle directory Resources/views/Field/ezxmlfield.html.twig

And the content of this template is:

{% block ezxmltext_field %}
    {{ field.value.xml|xmltext_to_html5 }}
{% endblock ezxmltext_field %}

Now to use this new template you just have to call it in your templates when rendering a field of type xmlblock

{{ ez_render_field( content, 'my_xmlblock_field', {'template': 'MybaseBundle:Field:ezxmlfield.html.twig' } ) }}


The other way to do it is overriding the content_fields.html.twig

        eng:  # The siteaccess
                - { template: MyBaseBundle::content_fields.html.twig, priority: 10}

and you have to copy the main template from eZ Publish which is located at:


This file contains all the definitions for the stock data types from eZ Publish, after you have copied the file you should modify the block simple_block_field.

In this case when you want to render a xmlblock field is not necesary to include the template:

{{ ez_render_field( content, 'my_xmlblock_field' ) }}

and that's it

Modified on Monday 11 August 2014 11:02:23 pm by Ernesto Buenrostro

Tuesday 12 August 2014 9:54:27 am

Thank you very much. I chose override option using :

 {% block ezxmltext_field %}
    {% spaceless %}
        {% set field_value = field.value.xml|xmltext_to_html5 %}
        {{ field_value|raw }}
    {% endspaceless %}
{% endblock %}

Page are cleanner without those useless <a> and <div> .


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

36 542 Users on board!

Forums menu

Proudly Developed with from