[TYPO3-mvc] fluid <f:if > with a regular expression

Franz Koch typo3.RemoveForMessage at elements-net.de
Sat Jun 12 15:01:02 CEST 2010


Hi,

> <f:for each="{outstandignProjects}" as="project">
>              <div class="projectmini">
>                      <h4>{project.name}</h4>
>                      <f:format.crop maxCharacters="200"
> respectWordBoundaries="true"><f:format.html>{project.description}</
> f:format.html></f:format.crop>
>                      <f:for each="{project.images}" as="image">
>                          <f:if condition="preg_match('/Thumbnail/',
> {image.name})">
>                          <f:then>
>                              <f:image src="uploads/pics/{image.file}"
> alt="{image.alttext}" width="200px" />
>                          </f:then>
>                          </f:if>
>                      </f:for>
>              </div>
>
> I'm passing a project list as a parameter and each project has a relation
> with images

how about adding a additional method "getType" to your image object and 
let it return if the image is a thumbnail or a regular image, and in 
your template you then do the following:

<f:if condition="{image.type} == 'thumbnail'">
	<f:image src="uploads/pics/{image.file}" />
</f:if>


Or create a viewHelper like
<p:string.contains string="{image.name}" value="Thumbnail"/>
and use it in shorthand syntax inside the if viewHelper. That way it's 
not that technical like some preg_match stuff no average template-guy 
would understand.

-- 
kind regards,
Franz Koch


More information about the TYPO3-project-typo3v4mvc mailing list