Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Include components inside page
#1
Hello

I have 2 components that i want to include on different pages. how can i do that without creating a new template for that page?

thanks a lot.
Reply
#2
amaurib Wrote:Hello

I have 2 components that i want to include on different pages. how can i do that without creating a new template for that page?

thanks a lot.

Install the DynPages plugin and include the following on the page:
Code:
{% my-component-name %}
You can also pass parameters to the component.
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#3
This is what I'm using to manage and reuse components to be displayed outside the "page" wysiwyg editor. Sometimes some difference in the header, sidebar or other static area of the page is useful.

The i18n component is installed. For the sidebar it could be coded like this:

Code:
<div id="sidebar">
    <?php include('sidebar-social.inc.php'); ?>    // some static content

     <?php
        $page = (string) return_page_slug();
        // echo $page;  //uncomment to see the string for the active page
        if ($page == "index")  
            get_i18n_component('sidebar-custom-1');
        elseif ($page == "contact")
            get_i18n_component('sidebar-custom-1');
        elseif ($page == "testimonials")
            get_i18n_component('sidebar-custom-2');
        else
            get_i18n_component((string) return_page_slug()); // returns a component matching the name of the page
    ?>            

    <?php include('sidebar-portfolio.inc.php'); ?>  // some static content    
</div>


There is flexibility and simplicity ( thanks to GetSimple! ) and typing the php code for your needs is simple too. Your code needs to between "<?php" and "?>".

In the above code the sidebar-custom-1 component is used in the index and contact pages. And the sidebar-custom-2 component is used in the testimonials page. And if there is a component with the same name as the active page, it will display automatically via the code:

Code:
get_i18n_component((string) return_page_slug());

and, if none of the above criteria is met, then nothing is added to the sidebar.

I'm new to GetSimple, so please let me know if this flexibility is already handled elsewhere. I didn't find much about making custom code for individual pages and pieced this code from the excellent documentation for the i18n and other plugins. Thank you.
Reply
#4
DonR Wrote:This is what I'm using to manage and reuse components to be displayed outside the "page" wysiwyg editor. Sometimes some difference in the header, sidebar or other static area of the page is useful.

The i18n component is installed. For the sidebar it could be coded like this:

Code:
<?php
        $page = (string) return_page_slug();
        // echo $page;  //uncomment to see the string for the active page
        if ($page == "index")  
            get_i18n_component('sidebar-custom-1');
        elseif ($page == "contact")
            get_i18n_component('sidebar-custom-1');
        elseif ($page == "testimonials")
            get_i18n_component('sidebar-custom-2');
        else
            get_i18n_component((string) return_page_slug()); // returns a component matching the name of the page
    ?>

I'm new to GetSimple, so please let me know if this flexibility is already handled elsewhere. I didn't find much about making custom code for individual pages and pieced this code from the excellent documentation for the i18n and other plugins. Thank you.

This is exactly the easiest way to have custom sidebars.
You could of cause also test e.g. for the parent of a page like
Code:
if (return_parent() == "products") get_i18n_component('sidebar-products');
to have all products with parent page "products" have the same sidebar ;-)

There is another possibility, if you have only a few custom sidebar components, but lots of pages and want to assign components to pages. You can use the I18N Custom Fields plugin and configure it to have a dropdown field (named e.g. 'sidebar-component') with all possible component names. Then this dropdown field will be shown on every page edit view and you can choose a component to display in the sidebar.
In the template you would just include
Code:
get_i18n_component(get_custom_field('sidebar-component', 'name-of-default-component'));
which will display the selected component or the component name-of-default-component if nothing is selected on the page.
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply




Users browsing this thread: 1 Guest(s)