Ah, ok. I was hoping a slot would work for me but yes, using another macro will 
work exactly as I need it to :)

Thanks,

robert

On 5 May 2010, at 14:50, Kornel Lesiński wrote:

> On 05-05-2010 at 14:26:08 Robert Goldsmith <rgoldsm...@names.co.uk> wrote:
> 
>> Just a quick one. Could someone tell me how to reference a variable defined 
>> within a metal macro from within a slot?
> 
> You can't. Slots aren't filled on demand, but in advance before the macro is 
> called (slot in a loop would repeat the same content over and over).
> 
>> In particular, I'd like to define a macro that generates a calendar grid of 
>> days and then use a slot to provide varying content to be rendered within 
>> the 'day' cells. I am trying to do this as a macro accepting an array and 
>> looping through the array content. This works fine but when I then try to 
>> split out the cell content into a slot, I receive errors that I can't access 
>> the current loop value (or, by my understanding, any other variables defined 
>> within the metal macro) from the slot.
>> 
>> A quick (very simplified) example...
>> 
>> The macro block (in macro.xhtml):
>> <tal:block>
>>      <table metal:define-macro="calendarMonthGrid">
>>              <thead>
>>                      <tr>
>>                              
>> <th>monday</th><th>tuesday</th><th>wednesday</th><th>thursday</th><th>friday</th><th>saturday</th><th>sunday</th>
>>                      </tr>
>>              </thead>
>>              <tbody>
>>                      <tal:block tal:repeat="currentDay days">
>>                              <td>
>>                                      <tal:block 
>> metal:define-slot="calendarDayContent" />
>>                              </td>
>>                      </tal:block>
>>              </tbody>
>>      </table>
>> </tal:block>
> 
> You could change:
> 
>>                                      <tal:block 
>> metal:define-slot="calendarDayContent" />
> 
> to:
> 
>>                                      <tal:block 
>> metal:use-macro="${calendarDayMacro}" />
> 
> And instead of filling slot, define macro for day:
> 
> <span metal:define-macro="dayMacro" 
> tal:content="currentDay/someInterestingInfo" />
> 
> <tal:block tal:define="days monthDays; calendarDayMacro 
> string:thisfile.xhtml/dayMacro" 
> metal:use-macro="macro.xhtml/calendarMonthGrid">
> 
> 
> -- 
> regards, Kornel
> 
> _______________________________________________
> PHPTAL mailing list
> PHPTAL@lists.motion-twin.com
> http://lists.motion-twin.com/mailman/listinfo/phptal


_______________________________________________
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal

Reply via email to