Closed jopaul-10 closed 6 years ago
Hmm, a horrible way to do this would be $getField('Title')
in the template...
Thanks for suggestion. I used a similar approach by extending Widget.PHP and adding WidgetTitle () and then using $WidgetTitle instead of $Title in the front-end.
I.e: " public function WidgetTitle () { $title = $this->getField ("Title"); if ($title && $title != false && $title != NULL) { return $title; } }"
Yep, that's the other approach - pretty horrible.
I'm not sure why Title returns a default value which is the name of the class :/
I'm not clear on the best approach to fix this. Perhaps we could remove the functionality that returns the class name in the Title by default. I suppose we could make the behaviour configurable and have it enabled by default to prevent this being a major semver change?
I would probably only patch this in the next major release.
Cool, re-labelled as SS4
This change has been made in the SS4 compatible version of the widgets module.
Hi, I would like for Title to return NULL in the front-end when no title is entered in the Title field in the CMS.
Currently, when no title is entered in the CMS, $Title returns the widget's title - i.e. the name of the widget that is in the CMS. For example, if the widget is named "Right-side component", $Title returns "Right-side component" even if the Title field of the widget is left empty in the CMS.
I already tried several ways of doing this. All failed. Here are the methods I've tried:
"_config.yml" extension of Widget.PHP and overwriting the functions "Title ()" and "getTitle ()". Forcing a return with "return 'Title from MyWidgetExtension';" and "return 'getTitle from MyWidgetExtension';" both worked. But with "return False;" or "return NULL;", the front-end condition, "<% if $Title %>", still returns true.
"Class MyWidgetExtension extends Widget" extension of Widget.PHP. Same result as point 1.
It seems like there's no way for "<% if $Title %>" to return false like conditions on other fields does - e.g. "<% if $Subtitle %>" returns false when it's empty.
And I don't want to use "<% if $Title == '' %>" or "<% if $Title != '' %>" if there is a better way. And I also don't want to create a new field to use instead of Title.
Any ideas? Thanks!