Understanding block__*() delegate methods
Archived from the Xataface Users forum.
kedoin — Wed Apr 23, 2008 12:19 pm
In my Xataface app, I have a ‘people’ table. I wanted to create a new action which will allow users to send email to a result set from the ‘people’ table. To create the form for this, I wanted to use HTML_QuickForm, so I decided to implement block__main_section() in tables/people.php.
This seems to work. When I use my email action, the form I’ve begun to specify appears. Now here’s where I get confused. I would think that since I am overriding this block__ method, that the form would end up showing up on all pages for the ‘people’ table. But, I haven’t found it showing up on any of the oages such as “details”, “list”, “new record”. I’m not complaining as I only wanted them to show up for my email action. However, I don’t understand why the main_section I defined in the delegate isn’t showing up in more places. I guess another way of asking my question is how do I make sure this email form only appears in my email action and not in the main_section of some other action on the ‘people’ table?
Thank you,
-Rob
shannah — Thu Apr 24, 2008 9:10 am
This can be a little confusing. A slot can be overridden in two ways.
-
implement the block__slotname() method in the delegate class.
-
Inherit from the template using the {use_macro} tag, and then fill the slot using the {fill_slot} tag.
If a template is derived from another template using the {use_macro} tag, and it overrides a slot via the {fill_slot} tag, then effectively the slot is no longer available to be overridden, unless the template defines a new slot of the same name.
e.g.
MyTemplate.html extends from Dataface_Main_Template.html:
- Code: Select all
- `{use_macro file=”Dataface_Main_Template.html”}
{fill_slot name=”main_section”}My custom content in the main section
{/fill_slot}
{/use_macro}`
Now we can no longer override the main_section slot for this template, because it has already been used.
We could redesign this template to still allow us to override the main_section slot:
- Code: Select all
{use_macro file="Dataface_Main_Template.html"} {fill_slot name="main_section"} {define_slot name="main_section"} My custom content in the main section {/define_slot} {/fill_slot} {/use_macro}
This is why your block__main_section() is not overriding many of the templates. It is because those templates already implement that slot.
If you are doing a custom action for your email form, it is better to create a template that inherits from the Dataface_Main_Template.html template than to implement the block__main_section() method. That way you don’t have to worry about undesired side-effects.