Skip to content

Instantly share code, notes, and snippets.

@RubaXa
Created Nov 16, 2012
Embed
What would you like to do?
xtpl vs. fest

Fest

<?xml version="1.0"?>
<fest:template xmlns:fest="http://fest.mail.ru" context_name="json">
	<div class="elm">
		<fest:attributes>
			<fest:attribute name="id">box</fest:attribute>
			<fest:attribute name="style">color: red;</fest:attribute>
			<fest:attribute name="class"><fest:space/>js-elm</fest:attribute>
			<fest:if test="false">
				<fest:attribute name="style">display: none;</fest:attribute>
			</fest:if>
			<fest:choose>
				<fest:when test="ctx.disabled"><fest:attribute name="class"><fest:space/>disabled</fest:attribute></fest:when>
				<fest:otherwise>
					<fest:attribute name="class"><fest:space/>active</fest:attribute>
					<fest:attribute name="style">font-weight: bold;</fest:attribute>
				</fest:otherwise>
			</fest:choose>
		</fest:attributes>
		<a>
			<fest:attributes>
				<fest:attribute name="href">#</fest:attribute>
			</fest:attributes>
			<br>
				<fest:attributes>
					<fest:attribute name="clear">all</fest:attribute>
				</fest:attributes>
			</br>
		</a>
	</div>
</fest:template>
<div class="elm" id="box" style="color: red;" class=" js-elm" class=" active" style="font-weight: bold;">
    <a href="#"><br clear="all"/></a>
</div>

xtpl

<x:tpl>
	<div class="elm">
		<x:attr name="id">box</x:attr>
		<x:attr name="style">color: red;</x:attr>
		<a>
			<x:attr name="href">#</x:attr>
			<br>
				<x:attr name="clear">all</x:attr>
			</br>
		</a>
		<x:attr name="class"> js-elm</x:attr>
		<x:if test="false">
			<x:attr name="style">display: none;</x:attr>
		</x:if>
		<x:choose>
			<x:when test="ctx.disabled"><x:attr name="class"> disabled</x:attr></x:when>
			<x:otherwise>
				<x:attr name="class"> active</x:attr>
				<x:attr name="style">font-weight: bold;</x:attr>
			</x:otherwise>
		</x:choose>
	</div>
</x:tpl>
<div id="box" style="color: red;font-weight: bold;" class="elm js-elm active">
     <a href="#"><br clear="all"/></a>
</div>

Bonus

По умолчанию, атрибуты добавляются, но можно и полностью заменить, добавив replace:

    <x:attr name="style" replace="true">color: green;</x:attr>

Experiment

<x:tpl>
	<div class="el">
		<div>
			Hello,<x:space/>
			<b>
				@x:class = "fail";
				@x:class = "ok";
				World!
			</b>
			@x:class = "minus";
			@x:class = "plus";
		</div>
		@x:class = "active";
		<x:if test="false">
			@x:class += " js-fail";
		</x:if>
		@x:class += " js-el";
	</div>
</x:tpl>
<div class="active js-el"><div class="plus">Hello, <b class="ok">World!</b></div></div>
@RubaXa

This comment has been minimized.

Copy link
Owner Author

@RubaXa RubaXa commented Nov 16, 2012

По умолчанию, атрибуты добавляются, но можно и полностью заменить, добавив replace :]

<x:attr name="style" replace="true">color: green;</x:attr>
@RubaXa

This comment has been minimized.

Copy link
Owner Author

@RubaXa RubaXa commented Nov 16, 2012

еуые

@RubaXa

This comment has been minimized.

Copy link
Owner Author

@RubaXa RubaXa commented Nov 16, 2012

3252352 53

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment