Triggering Contents Plugins to create a customized layout of your fields, to e.g. Sliders or Tabs/ render a google maps plugin /etc

  • Published by
    George Papadakis
  • Last modified
    25 January 2019
  • Up to date
    Yes
  • Profile concerned
    Webdesigner, Developer
  • Concerns
    Component Template
  • Since Version
    1.5.4
  • Voting
    Average rating
    5 votes
    • 1
    • 2
    • 3
    • 4
    • 5
  • Favourites
    278 Triggering Contents Plugins to create a customized layout of your fields, to e.g. Sliders or Tabs/ render a google maps plugin /etc /documentation/tutorials-english/71-fields-usages-tips-joomla-plugin/278-triggering-contents-plugins-to-create-a-customized-layout-of-your-fields-to-eg-sliders-or-tabs-render-a-google-maps-plugin-etc.html

Some times it is desired to create a customized layout of your fields for item or category view ...
e.g. to create a layout with tabs or sliders containing the display of various fields ...

-- a. First duplicate one of flexicontent templates e.g. 'default' to 'mydefault'

-- b. Edit Content Type e.g. 'Article' to use as predefined item layout the one from 'mydefault'

-- c. In templates management edit item layout of template 'mydefault', and places ALL fields you wish to use in the 'renderonly' position, e.g. fields 'myfielda', 'myfieldb', 'myfieldc'

-- d. Edit file: components/templates/mydefault/item.php and add this code inside it, at appropriate place:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 
// STEP 1. Create an empty object c
$c = new stdClass();
 
// STEP 2. Prepare your some text to trigger Content plugins on
// *** NOTICE *** bellow besides ->display, you can use also use ->value[0] OR ->value[0]['property_name1']
$c->text = ''; $c->text .= '{some_plugin_code}'; $c->text .= $this->item->fields['myfielda']->display; $c->text .= '{some_plugin_code}'; $c->text .= $this->item->fields['myfieldb']->display; $c->text .= '{some_plugin_code}'; $c->text .= $this->item->fields['myfieldc']->display; $c->text .= '{some_plugin_code}';


  // STEP 3. Prepare other properties of the object c, so that it looks like a Joomla article object $c->title = $this->item->title; $c->slug = $this->item->slug; $c->catid = $this->item->catid; $c->catslug = $this->item->categoryslug; $c->id = $this->item->id; $c->state = $this->item->state;   // STEP 4. Trigger the content plugins $dispatcher = &JDispatcher::getInstance(); JPluginHelper::importPlugin('content'); $results = $dispatcher->trigger('onContentPrepare', array ('com_content.article', &$c, &$this->params, 0));   // STEP 5. Output the created HTML echo $c->text;