how to include a page in another page ?

vincent3569 Member, Translator
hi

I have a page called "license" (and with a TitleLink called 'license').
I have another page called "theme".

I want to include licence page content in theme page.

I add this code in codeblock, but it doesn't work :
`<?php printPageContent('license'); ?>`

How should I do that ?
Is there a content macro to do that ?

Comments

  • acrylian Administrator, Developer
    1.4.5.9 or 1.4.6?

    `<?php printPageContent('license'); ?>`
    That should work. You need to set the 2nd parameter if it is an unpublished page.

    Beside that the object model should always work (Which this uses internally):
    `
    $page = new ZenpagePage('license');
    echo $page->getContent();
    `
  • vincent3569 Member, Translator
    my page was unpublished, so, I have to set 2nd parameter...

    is there a macro do do that (insert page contents anywhere in another page content) ?
  • acrylian Administrator, Developer
    No, no macro for that exists currently. All can be done, could be part of Zenpage but will have to wait after 1.4.6. then. Or an independent plugin like this https://github.com/acrylian/zenpage_subpages.

    You can enable the macro plugin to get a list of all available macros.
  • acrylian Administrator, Developer
    No, no macro for that exists currently. All can be done, could be part of Zenpage but will have to wait after 1.4.6. then. Or an independent plugin like this https://github.com/acrylian/zenpage_subpages.

    Seems usefull so I might give it a shot the next days as an "half official" plugin.

    Btw, you can enable the macro plugin to get a list of all available macros.
  • vincent3569 Member, Translator
    hi

    I had a look on your plugin that add a content macro and I read content macro tutorial (http://www.zenphoto.org/news/content-macros).
    I have questions about macro :
    - what are the differences between procedure, function and expression ?
    - in your plugin, you have `$plugin_is_filter = 9|THEME_PLUGIN|ADMIN_PLUGIN;`, but in tutorial, `$plugin_is_filter = 5|THEME_PLUGIN|ADMIN_PLUGIN;` is mentioned : what is the difference between 5 an 9 (please, don't answer 4 :-) )
  • vincent3569 Member, Translator
    this plugin doesn't work

    `
    <?php
    /**
    * Provides a content macro to print a page content (not subpages and not extra content) where it called from :
    *
    * Content macro:
    * [PAGE_CONTENT string %1 {bool %2}]
    *
    * @license GPL v3
    * @author Vincent Bourganel (vincent3569)
    *
    * @package plugins
    * @subpackage misc
    */
    $plugin_is_filter = 9|THEME_PLUGIN|ADMIN_PLUGIN;
    $plugin_description = gettext('A plugin to print a page content (not subpages and not extra content) where it called from');
    $plugin_author = 'Vincent Bourganel (vincent3569)';
    $plugin_version = '1.0';

    zp_register_filter('content_macro','zenpagePageContent::pageContent_macro');

    class zenpagePageContent {

    function __construct() {
    }

    /*
    * macro definition
    * @param array $macros
    * return array
    */
    static function pageContent_macro($macros) {
    $macros['PAGE_CONTENT'] = array(
    'class' => 'function',
    'params' => array('string','bool*'),
    'value' => 'getPageContent',
    'owner' => 'zenpageContentPage',
    'desc' => gettext('Prints a page content where it called from : string %1 is titlelink of the page, optional bool %2 is set to false if you want to call an un-published page\'s (true is default value)')
    );
    return $macros;
    }

    } // class end
    `
    in macro tab, I have this Warning:

    `
    [PAGE_CONTENT string %1 {bool %2}] (zenpageContentPage)
    Prints a page content where it called from : string %1 is titlelink of the page, optional bool %2 is set to false if you want to call an un-published page's (true is default value)
    Warning:

    getPageContent is not callable
    `
    thanks in advance to point me in the right direction.
  • acrylian Administrator, Developer
    The answer is of course 42 :-) Seriously that is the priority of the plugin load order.

    From a quick look: Your plugin does not work because you have to define the actual funtion to return the content of the macro. Calling outside functions does not work because of the parameters.

    But you don't need to bother, I have a plugin on my list for articles and pages content already so if you can wait 1-2 days.
  • vincent3569 Member, Translator
    of course, I can wait if somebody does the job for me ;-)
    but, I would like to understand where is the matter...

    in exempleMacro, there is CODEBLOCK macro which refer to outside function, and it works
    `
    [...]
    'CODEBLOCK' => array(
    'class' => 'procedure',
    'params' => array('int'),
    'value' => 'printCodeblock',
    'owner' => 'exampleMacros',
    'desc' => gettext('Places codeblock number %1 in the content where the macro exists.')),
    [...]
    `
  • acrylian Administrator, Developer
    Right, indeed, my mistake looking to quickly at it. I cannot answer right now without looking more at it. The difference is the "procedure" vs "function" and "get" vs "print":
    http://www.zenphoto.org/news/content-macros#standard-macros
  • vincent3569 Member, Translator
    this plugin works :

    `
    <?php
    /**
    * Provides a content macro to print a page content (not subpages and not extra content) where it called from :
    *
    * Content macro:
    * [PAGE_CONTENT string %1 {bool %2}]
    *
    * @license GPL v3
    * @author Vincent Bourganel (vincent3569)
    *
    * @package plugins
    * @subpackage misc
    */
    $plugin_is_filter = 9|THEME_PLUGIN|ADMIN_PLUGIN;
    $plugin_description = gettext('A plugin to print a page content (not subpages and not extra content) where it called from');
    $plugin_author = 'Vincent Bourganel (vincent3569)';
    $plugin_version = '1.0';

    zp_register_filter('content_macro','zenpage_PageContent::pageContent_macro');

    class zenpage_PageContent {

    function __construct() {
    }

    static function getContent_Page($titlelink, $published = true) {
    $page = new ZenpagePage($titlelink);
    if (($page->getShow()) || ((!$page->getShow()) && (!$published))) {
    echo html_encodeTagged($page->getContent());
    } else {
    echo html_encodeTagged('');
    }
    }

    /*
    * macro definition
    * @param array $macros
    * return array
    */
    static function pageContent_macro($macros) {
    $macros['PAGE_CONTENT'] = array(
    'class' => 'procedure',
    'params' => array('string','bool*'),
    'value' => 'zenpage_PageContent::getContent_Page',
    'owner' => 'zenpageContentPage',
    'desc' => gettext('Prints a page content where it called from : string %1 is titlelink of the page, optional bool %2 is set to false if you want to call an un-published page\'s (true is default value)')
    );
    return $macros;
    }

    } // class end
    `
    but I don't realy understand why external core function can't be called.
    to create some content macro, you have to the job twice (create a function that already exists)
  • acrylian Administrator, Developer
    I cannot answer at the moment I mostly go this way, too. Could be the owner maybe. I always tend to use the object model instead of template functions. For extra content fields you even have to as you cannot call them directly otherwise, those my plugin was meant to support as well.
  • vincent3569 Member, Translator
    your plugin will be most robust and complete than mine.

    but 2 questions :
    1- what are the differences between procedure, function and expression ?
    2- how avoid html error generated by tinyMCE ?

    for the 2nd question, some explanation :
    in tyneMCE, I added my macro like that [PAGE_CONTENT 'license' false].
    tyneMCE automaticaly wrapped this text by `

    ` html tag.
    but as I insert my page content, it generate wrong html flow like

    `


    blabla

    blabla

    `
  • acrylian Administrator, Developer
    Mine is not that much different from yours, just a bit more complete:
    https://github.com/acrylian/zenpage_content

    Regarding the wrong html I fear there is no easy way to prevent that. When the macro is entered TinyMCE by default wrapps it with a paragraph as with all text you enter. It does not "know" that that also prints html on the front end. The only way would be to disable this behaviour but that causes other issues. Actually we then had to replace line breaks with paragraphs and such before outputting anything.

    I am honest I cannot exactly explain the difference between procedure, function and expression types. For procedure and function it is probably that the first works with functions that print/echo something while the function one uses return values and prints them itself. The doc needs to be clearer with the actual differences.
  • acrylian Administrator, Developer
    I just looked all plugins I did with macros use only the function and sometimes the constant one.
  • vincent3569 Member, Translator
    ok

    tkanks for the plugin (and the inspiration :-)

    some comments about it :
    according to me
    - the first paramater (titlelink) should be mandatory in all macro (lines 77, 84, 91, 98)
    - the parameter `$titlelink` shouldn't have a default value `$titlelink = ''` (lines 31, 35, 38, 42)
    - maybe, you can aslo create a macro toi display and exerpt of the latest news
    - all your macros (include zenpage_subpages) should be macro of zenpage plugin and added to the plugin (as SLIDESHOW macro is included in slideshow plugin).
  • acrylian Administrator, Developer
    Indeed, the first should be and is technically as it does not make any sense to not set it ;-)

    Those could be part of Zenpage but maybe it would make sense to keep them separate but collect in one. In any case for 1.4.6 we have feature freeze already.

    Update: I have renamed the repo to "zenpage_macros" and will merge it to a plugin of the same name. I can later decide if this gets incorporated into Zenpage as well.

    Update 2: I have now merged both and renamed the plugin. Please test so I have no type anywhere :-) https://github.com/acrylian/zenpage_macros
    Latest news sounds like a good idea, although it will have the same issue with tinymce and paragraph wrappers.
Sign In or Register to comment.