Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1397005

    Hi Support,

    I was wondering if there was a way to use a custom template part that is tied to a custom element template.

    For example, I am using Advanced Custom Fields and let’s say my custom template part looked something like the following:

    <?php
    /**
     * Breaker bar
     * 
     * @param string title
     * @param string summary
     */
    ?>
    <?php 
        $title = get_field('breaker_title');
        $summary = get_field('breaker_summary');
    ?>
    ​
    <section class="breaker">
    	<div class="container">
    		<div class="breaker-box">
    			<div class="breaker-content">
    				<h2 class="breaker-title"><?php echo $title; ?></h2>
    				<span class="breaker-summary"><?php echo $summary; ?></span>
    			</div>
    		</div>
    	</div>
    </section>

    Do you have a base file that I can put in the config-templatebuilder/avia-shortcodes/ that has something like “_get_template_part” to return the above component to where ever the custom element template (CET) was placed on a page?

    I did think about creating an actual page template but that would then mean the components are hardcoded to the page, and it would be nice if the user could place that component wherever they wanted on the page.

    I’m aware I can modify one of the avia-shortcodes by including it in my child theme, but they all seem to be quite large, I assume because they have all the extra customisation options for the particular component you have copied, but I wouldn’t require those (styling tab, development tab etc), I just want some code to be outputted.

    Thanks
    Sean

    #1397070

    Hey MotiveAgency,

    Thank you for the inquiry.

    We are not really sure what you are trying to do, but there is a core function called get_template_part, which allows you to load a template to another. Please check the documentation below for more info.

    // https://developer.wordpress.org/reference/functions/get_template_part/

    Best regards,
    Ismael

    #1397145

    Hi Ismael,

    Thanks for getting back to me and apologies that my topic wasn’t well explained. I’ll try and rephrase:

    I am trying to create a custom element in the “/config-templatebuilder/avia-shortcodes/” I am after a PHP file that only includes the required code to output some basic HTML.

    For example, I have taken the hr.php file (“/config-templatebuilder/avia-shortcodes/hr/hr.php”) assuming that would be one of the components with the least amount of code, and removed the following functions:

    Line 59: popup_elements()
    Line 138: register_dynamic_templates()
    Line 329: get_element_styles()

    I then created the following directory in my child theme “/config-templatebuilder/avia-shortcodes/custom/” and renamed and saved the hr.php file as custom.php to this directory.

    You may mention that some of the above functions are required for the component to output correctly. I assume shortcode_insert_button(), editor_element( $params ) and shortcode_handler( $atts, $content = ”, $shortcodename = ”, $meta = ” ) are required?

    I’m after a minimal starting component file that I can work from to create custom components at (“/config-templatebuilder/avia-shortcodes/”) rather than modifying/overwriting existing ones using my child theme.

    I hope that makes sense.

    Thanks
    Sean

    #1397261

    Hi,

    Thank you for the clarification.

    I then created the following directory in my child theme “/config-templatebuilder/avia-shortcodes/custom/” and renamed and saved the hr.php file as custom.php to this directory.

    In order to create a new shortcode/element or override existing ones in the child theme, you will have to register another shortcode path using the avia_load_shortcodes filter. The code is provided in the documentation below.

    // https://kriesi.at/documentation/enfold/intro-to-layout-builder/#add-elements-to-alb

    You can then create a folder called “shortcodes” in the child theme directory and create custom elements by copying the folder structure in the avia-shortcodes directory.

    I’m after a minimal starting component file that I can work from to create custom components at (“/config-templatebuilder/avia-shortcodes/”) rather than modifying/overwriting existing ones using my child theme.

    You lost me here for a bit. If I understood correctly, you are trying to create a new element based on existing templates in your child theme. Is that correct? For starters, you might want to copy an existing element from the parent theme, put it in the “shortcodes” folder in the child theme, edit the info in the shortcode_insert_button function, then modify the output in the shortcode_handler function. You can then strip out what you don’t need or extend it as necessary.

    Best regards,
    Ismael

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.