[PHPTAL] Imploding tal:attributesfrom source array
Anton Andrievskij
x.meglio at gmail.com
Tue Jan 29 12:12:18 CET 2008
Ok, I see the problem. Probably you can try to use something like this then:
in your php code:
*$imgTag = '<img ';
foreach($attributes as $attrname => $attrvalue)
$imgTag .= "$attrname=\"$attrvalue\" ";
$imgTag .= '/>';
$templateObject->imgTag = $imgTag;*
In your template:
*<span tal:replace="structure ${imgTag}"/>*
On Jan 29, 2008 9:10 AM, Werner <lists at mollentze.co.za> wrote:
> Hi Anton
>
> Unfortunately this does not seem to work. It seems that there needs to
> be at least one attribute key to be specified before the attribute's
> value will be rendered.
>
> E.g. if you use:
> <img tal:attributes="${imgAttr}" />
> You get:
> <img/>
>
> I ony can get something rendered if I specify an attribute name:
> <img tal:attributes="myattrs ${imgAttr}" />
> You get:
> <img myattrs=" id some_id; class some_class; src img/beautiful.jpg;"/>
>
> Why is this so hard? One would almost expect tal:attributes to be able
> to handle any assoc array right there in place? E.g.
> <img tal:attributes="${myAssocArray}" />
>
> I guess this is not the intended way, eh? The only alternative seems to
> be to write a very long tal:attributes definition that would cater for
> any possible attribute, but I;m sure there must be a better approach...?
>
> Kind Regards,
> Werner
>
> Anton Andrievskij wrote:
> > In your PHP:
> >
> > *$imgAttr = '';
> > foreach($attributes as $attrname => $attrvalue)
> > $imgAttr .= "$attrname $attrvalue;";
> >
> > $templateObject->imgAttr = $imgAttr;*
> >
> > In your template:
> > *<img tal:attributes="${imgAttr}" />*
> >
> > Hope this may help.
> > Anton Andryevskyy
> >
> > On Jan 29, 2008 12:30 AM, Werner <lists at mollentze.co.za
> > <mailto:lists at mollentze.co.za>> wrote:
> >
> > Hi!
> >
> > Has anyone found an easy (and readable) way to do the following by
> > using
> > tal:attributes ?
> >
> > 1) You have an $attributes array in php:
> > $attributes = array('id' => 'some_id', 'class' =>
> 'some_class',
> > 'src' => 'img/beautiful.jpg');
> >
> > 2) You want to apply all the attributes as an element's attributes:
> > <img id="some_id" class="some_class"
> src="img/beautiful.jpg"/>
> >
> > Kind Regards,
> > Werner
> >
> >
> > _______________________________________________
> > PHPTAL mailing list
> > PHPTAL at lists.motion-twin.com <mailto:PHPTAL at lists.motion-twin.com>
> > http://lists.motion-twin.com/mailman/listinfo/phptal
> >
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > PHPTAL mailing list
> > PHPTAL at lists.motion-twin.com
> > http://lists.motion-twin.com/mailman/listinfo/phptal
> >
>
>
> _______________________________________________
> PHPTAL mailing list
> PHPTAL at lists.motion-twin.com
> http://lists.motion-twin.com/mailman/listinfo/phptal
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.motion-twin.com/pipermail/phptal/attachments/20080129/b0aa4f81/attachment.htm
More information about the PHPTAL
mailing list