[TYPO3-mvc] Extend CropViewhelper
Thomas Allmer
at at delusionworld.com
Mon Oct 10 18:26:43 CEST 2011
hey Tim,
thank you for your Example... and indeed it's working... I guess I was
just thinking to complicated :/
also thank you Sebastian for actually pointing in the right direction -
my bad that I didn't get it :p
anyway the working version :)
https://gist.github.com/1274313
also feels a little hackish but definitely better :)
cheers
On 10.10.2011 15:31, Tim Schoch | GSTALTIG wrote:
> Hello Thomas
>
> This works fine for me:
> <?php
> class ExtendedCrop extends CropViewHelper {
> protected function renderChildren() {
> return 'Child + ' . parent::renderChildren();
> }
> }
>
> class CropViewHelper { // imagine this to be the original fluid viewhelper
> public function render() {
> return $this->renderChildren();
> }
> protected function renderChildren() {
> return 'Parent';
> }
> }
>
> $crop = new ExtendedCrop();
> echo $crop->render(); // returns Child + Parent
> ?>
>
> The call in the parent $this->renderChildren() will call you're extended function and not the one defined by itself.
> If you want to preprocess the content before it gets cropped, you can do use the parent::renderChildren() method in your extended version.
> I guess thats what Sebastian meant.
>
> Tim
>
> _____
>
> From: Thomas Allmer [mailto:at at delusionworld.com]
> To: typo3-project-typo3v4mvc at lists.typo3.org
> Sent: Mon, 10 Oct 2011 13:50:37 +0200
> Subject: Re: [TYPO3-mvc] Extend CropViewhelper
>
> On 10.10.2011 09:17, Sebastian Schreiber wrote:
> > Maybe this helps and make you feel better:
> >
> > Introduce a member variable in your class overrite the renderChildren
> > method in your class and return your
> > variable.
> >
> > Right?
>
> probably not :p
>
> changing the renderChildren method won't change how the parent will
> fetch it's string... so it won't help :p unless I extend the Crop with a
> "CropFix" overwriting the renderChildren there and then extend from the
> "CropFix" instead of the normal Crop... but than again this looks even
> more ugly :p and if I would crop I would certainly only change the
> render method so I could pass the string to use and not temper with the
> renderChildren :p
>
> more ideas? :p
>
> > Am 10.10.2011 01:00, schrieb Thomas Allmer:
> >> hey,
> >>
> >> can I set somehow the content of the current viewhelper?
> >> I do want to extend the CropViewHelper like this:
> >>
> >> class Tx_Reposearch_ViewHelpers_Format_HighlightCropViewHelper extends
> >> Tx_Fluid_ViewHelpers_Format_CropViewHelper
> >>
> >> so I get the string and do some modifications to it afterward I want
> >> to call the parent, but as Crop gets the content with
> >> $this->renderChildren(); I can't give my "new" string as a parameter?
> >>
> >> I though of probably something like this but that obviously don't work
> >> as there is no setContent function :p
> >> $this->setContent($stringToHighlightTruncate);
> >> return parent::render($maxCharacters, $append, [...]);
> >>
> >> so currently I more or less just fork the Crop viewhelper... but that
> >> doesn't seem right... so anyone got a better solution?
> >>
> >> see gist for full code https://gist.github.com/1274313
> >>
> >> I was just thinking, but in most cases I don't even need this as most
> >> viewhelpers do it like this and let you define the subject via
> >> parameter...
> >> if ($subject === NULL) {
> >> $subject = $this->renderChildren();
> >> }
> >>
> >> so probably a bug report for a view?
> >>
> >> cheers
> >
> >
>
>
> --
> +---------------------------------+-----------------------------------+
> | Thomas Allmer | http://www.delusionworld.com |
> | E-mail: at at delusionworld.com | phone: +43 699 16217064 |
> +---------------------------------+-----------------------------------+
> _______________________________________________
> TYPO3-project-typo3v4mvc mailing list
> TYPO3-project-typo3v4mvc at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
>
--
+---------------------------------+-----------------------------------+
| Thomas Allmer | http://www.delusionworld.com |
| E-mail: at at delusionworld.com | phone: +43 699 16217064 |
+---------------------------------+-----------------------------------+
More information about the TYPO3-project-typo3v4mvc
mailing list