keeping field contents out of page source

chris.paschen

Chris Paschen
I am creating a custom Details View layout for a form (only used for display purposes).

I have a 3 elements:
* display_method
* code_name
* real_name

The elements are just fields and are all 'hidden'.

In the view I am checking to see what 'display_method' is set. Based on that I display the code_name or the real_name. However, in order to make that work both elements need to be published and available - which means that they appear in the page source.

Is there any way to make them available to the view without being displayed in the page source?

I know I shouldn't be doing functions in the layout - so if this is just a generally bad thing (or can't be easily solved) I'll just have to create a new view in the db and handle the processing from there.

But I just want to make sure that I'm not missing anything.
 
OK, we have a terminology barrier here. The words template, view and layout refer to entirely different things.

The 'view' is something like this:

components/com_fabrik/views/form/view.html.php

... which assembles and renders the various data structure required for output of the particular format (in this case, html), where the output is (usually) done by a template.

A layout is something like this:

components/com_fabrik/layouts/fabrik-button.php

... which renders a specific bit of markup, in a way that can be overridden, for example in site template layouts (often to account for different frameworks, like bootstrap v2 vs v3). Usually called from the guts of an extensions, as part of the rendering of specific content kicked off by the view.

A template is something like this:

components/com_fabrik/views/form/tmpl/bootstrap

... which is called from the 'view' to output the rendered data the view assembled.

I presume, when you talk about "doing functions in the layout", you actually mean "in the template"?

Just want to make sure before we go any further.

-- hugh
 
Sorry about the confusion (but I'm kinda glad ... that was a GREAT explanation of terminology ... it should go in the WIKI!).

But yes, you are correct, I'm working in the TEMPLATE (/components/com_fabrik/views/details/tmpl/custom-template/ etc.)
 
In which case, you control what gets rendered to the page.

Which template file are you working with? I'd probably do it with a condition at the top of the main foreach() loop, and just skip the one I don't want ...

Code:
foreach ($this->elements as $element) :
   if ($element->id === 'yourtable___code_name' && $this->elements['display_method']->element_raw === 'not the one for code_name'):
      continue;
   endif;
   if ($element->id === 'yourtable___real_name' && $this->elements['display_method']->element_raw === 'not the one for real_name'):
      continue;
   endif;
...
endforeach;

Replace stuff in quotes to suit.

That way it'll just render normally, but skip rendering the name you don't want.

-- hugh
 
Sorry I'm not understanding how to use this (it's Friday and too many brain cells used up this week :-0)

What is is the 'code_name" and 'real_name' referring to?
And how does this prevent these items from appearing in the source code of the page?

(I'm working on a copy of the default template. Although I've gutted it quite a bit to just show a few elements.)
 
What do you mean with "I'm working on a copy of the default template"? In Fabrik3 there's no "default" template, only bootstrap and bootstrap_tabs.
But anyway:
As long as you don't "echo" something there's nothing in the source code of the page.

default_group.php is doing this foreach() loop.
If you add Hugh's code it will skip ("continue;") the rest of the code in the loop, so skipping the output of the element you don't want to show.
 
Sorry I'm not understanding how to use this (it's Friday and too many brain cells used up this week :-0)

What is is the 'code_name" and 'real_name' referring to?
And how does this prevent these items from appearing in the source code of the page?

(I'm working on a copy of the default template. Although I've gutted it quite a bit to just show a few elements.)

Code:
   if ($element->id === 'yourtable___code_name' && $this->elements['display_method']->element_raw === 'not the one for code_name'):
      continue;
   endif;

The $element->id will be the full name of your element, so that tells us if in this iteration of the loop whether we are rendering the 'code_name' element. And if so, we need to know if the 'display_method' is set to the value that controls whether we use this, or 'real_name'. So, say we only want to show code_name if display_method is set to '1', and show 'real_name' if it is '2', then replace 'not the one for code_name' to '2', and that code will skip rendering code_name if display_method is 2.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top