View more context

 

nightjarnz

GroupedList caveat: that'll be a lot of PHP side processing.

taoceanz

Is it possible to use PHP functions in a .ss file? I'm rendering a view file and passing an array of data but want to check whether certain values exist within the array before displaying a section in that view file. I thought using in_array() or isset() would be sufficient but it's behaving like the function isn't being run.

nightjarnz

@taoceanz the way around this is to put the logic where it best belongs - this is likely your controller (assuming a page, eg. PageController), but could also be a model, etc. e.g.

  1. public function getThingExists($list) {
  2. return $list->filter('Key', $thing)->exists();
nightjarnz

That's a really bad example (code design wise), but hopefully conveys the idea.

taoceanz

Ok thanks @nightjarnz that's what I had thought was going to be the next step. The original purpose was to pass an array containing values from a shortcode to an includes file to specify which sections of that includes file would display without having to create a data object to store the individual sections.

But ok, I was just being lazy and trying to make it work an easy way. Thanks for the heads up. I'll create the datatype, generate the loopable object in the controller and pass that to the view to be rendered. Will make content admin easier in the future too.

nightjarnz

Well that should still be possible. You're looking for ArrayData

taoceanz

@nightjarnz I'm all good with the ArrayData & customise (I think). At a base, all I'm wanting to do is a check to see whether a variable exists in the view then display a section assuming it exists.

To give more context, I've created a footnotes include file that I'm displaying through a shortcode and pass a variable from the shortcode, through the shortcode handler function and is usable on the view that's being rendered.

If it were possible to check said variable in an 'if' statement, that should suffice for now.

E.G.

  1. [getfootnotestext footnotes='1,3,4']
  1. function getFootnotesText($footnotes){
  2. return new ArrayData(array_flip($footnotes));
  3. }
  1. <% if $footnotes.1 %> // display footnote 1
<% end_if %>
taoceanz

If 1, display 1. If 2, display 2.

Probably just get over this idea and create a new datatype.

Thanks for your feedback @nightjarnz

👍 (1)
nightjarnz

and ideally it should be a part of the shortcode handler, but the sounds.