Adding ability to append and prepend data to clips #626

Closed
wants to merge 2 commits into
from

Projects

None yet

4 participants

@MrTin
MrTin commented Apr 20, 2012

Hi!

We want to the ability to dynamically add more content to our clips so I added the properties $appendToClip and $prependToClip to CClipWidget

/Martin

@samdark
Member
samdark commented Apr 20, 2012

What's the use case for it?

@MrTin
MrTin commented Apr 20, 2012

Example, have the controller or extension add the clip and then be able to append to it in a view file.

@samdark
Member
samdark commented Apr 20, 2012

I meant real use example.

@cebe
Member
cebe commented Sep 3, 2012

@MrTin will close this as you gave no feedback for 5 month..

@cebe cebe closed this Sep 3, 2012
@motin
motin commented Jun 25, 2013

Also looking for this feature. Re-open or should I create a new PR?

Here is a real use case:
ModelA belongs to ModelB, ModelC and ModelD.

While rendering the update form for ModelA, "Add ModelX" buttons are included, which shows bootstrap modals containing create forms for the related models.

Since forms can't be included within each other, the markup for the modals needs to be included outside of the forms.

To support proper recursive rendering of nested relations and their respective modal forms, it makes sense to have each form append the markups for the modals to a clip named 'modals'.

The topmost parent form can then simply print out this clip outside of the original form.

@samdark
Member
samdark commented Jun 25, 2013

Can you show some code for it using the addition in the pull request?

@samdark samdark reopened this Jun 25, 2013
@motin
motin commented Jun 25, 2013
<?php
$this->beginClip('modals', array('appendToClip'=>true));
?>
Clip contents to append
<?php
$this->endClip();
?>
@motin
motin commented Jun 26, 2013

Caveat:
My proposed use-case has a flaw: When rendering clips recursively, several beginClip will reference the same id before the first endClip, causing only some clips to actually be appended to (the ones in the first level of recursion).
In other words: Clips do not support recursion, even with this pr (not surprising).
The ability to store markup for modals in some sort of ClipCollection to be rendered after a form, or at the end of body, is still desired. Currently had to resort to use clips with names like "modal:the-form-id" and then loop through the clips after the form and print out all beginning with "modal:".

@samdark
Member
samdark commented Jun 26, 2013

@motin do you have better solution? Is this pull request necessary considering what you've found out?

@motin
motin commented Jun 26, 2013

@samdark: A more general purpose solution for the use-case I mentioned above would be to have a similar method to CClientScript's registerScript, but for markup, so that chunks of markup can be inserted into the end of body while rendering the page. This makes sense for modals, dialogs etc that require markup.

@MrTin MrTin closed this Sep 18, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment