We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32241
    • 1,495 Posts
    I’ll will start my first contribution in the documentation then.

    Here is a set of API that you need to start making a chunk base template with placeholde.

    WARNING: mergeChunkContent & mergePlaceholderContent is not included as a global API for MODx. It might not be supported in the future release. You’ve been warned; use it with caution!



    setPlaceholder
    function setPlaceholder($name,$value)

    This API will basically store the $value variable into placeholders array with the associated key name from the given $name. The placeholder array, later will substitute the placeholder that are being included in a page (template, chunk, or content), with the format of "[+placeholder_name+]", without the quote.



    getPlaceholder
    function getPlaceholder($name)

    This is the opposite API of sePlaceHolder, which it will return the value of placeholder array with the given $name as the key name.



    parseChunk
    function parseChunk($chunkName, $chunkArr, $prefix="{", $suffix="}")

    We can use this function to substitute any special format string inside the chunk to be replaced by the value of the array. The given $chunkName will be the name for the chunk, and $chunkArr will be an associative array that is going to be used to substite the special format string inside the chunk, and the $prefix and $suffix is used to differentiate the special format string inside the chunk, default is "{" and "}". The associative array key name of $chunkArr will be used as a special format string name that is being prefixed by $prefix and $suffix. The $prefix and $suffix can be left blank for default value

    Example:

    This is an example of the chunk with the name "SampleChunk"
    This is the template
    Here is the special string format {SPECIAL1}
    


    This is an example of the snippet using parseChunk
    // Storing value to replace special format string into associative array
    $ChunkVar['SPECIAL1'] = "Hello World!";
    echo $modx->parseChunk("SampleChunk", $ChunkVar);
    


    The snippet above will output
    This is the template
    Here is the special string format [color=blue]Hello World![/color]
    





    The function listed under here is not suggested to be used for production snippet, plugin, or module!

    mergePlaceholderContent - WARNING: Non-Global API
    function mergePlaceholderContent($content)

    This function will combined the placeholders array that was set earlier (setPlaceholder) with the given string template, which was passed on to $content. It will replace "[+key_name+]" symbol in the template with the value on the array with the same key name. The rest of the placeholders symbol that are not associated with everything will be remove and substituted with empty string.


    mergeChunkContent - WARNING: Non-Global API
    function mergeChunkContent($content)

    This API will fetch a chunk based on their name, when it was stored inside the manager. We need to pass on a string with the format as when we are included chunk to the template or content "{{chunk_name}}", without the quote.


    Tips to use this for chunk base template on MODx Using Non-Global API
    Please read the example carefully, to get a grasp of the whole idea.
    $chunk_name = 'samplechunk'; // Assign chunk name to this variable
    // Setup placeholders
    $modx->setPlaceHolder('NamePlaceholder1', 'This is the value for placeholder 1');
    $modx->setPlaceHolder('NamePlaceholder2', 'This is the value for placeholder 2');
    // Getting chunk template and store it to variable
    $template = $modx->mergeChunkContent("{{".$chunk_name."}}")."\n";
    // Merging placeholder with template
    $output = $modx->mergePlaceholderContent($template);
    // Outputing result to the screen
    echo $output;
    




    Happy MODx-ing guys!
      Wendy Novianto
      [font=Verdana]PT DJAMOER Technology Media
      [font=Verdana]Xituz Media
      • 32241
      • 1,495 Posts
      Can moderator change the name of the topic to something more easier to find, so that everyone can start contributing to the core API documentation?

      Thanks
        Wendy Novianto
        [font=Verdana]PT DJAMOER Technology Media
        [font=Verdana]Xituz Media
      • Now "API Documentation". Thanks Wendy!
          Ryan Thrash, MODX Co-Founder
          Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
          • 32241
          • 1,495 Posts
          No problem Ryan. Hope my small contribution can help the community to grow even more.
            Wendy Novianto
            [font=Verdana]PT DJAMOER Technology Media
            [font=Verdana]Xituz Media
            • 32241
            • 1,495 Posts
            I just added the parseChunk API, and set a warning not to use non-public API.

            Thanks to Jason (OpenGeek). laugh
              Wendy Novianto
              [font=Verdana]PT DJAMOER Technology Media
              [font=Verdana]Xituz Media
              • 32241
              • 1,495 Posts
              OK another API question, what is this API do?

              function hasPermission($pm)

              Hope somone can answer it quick smiley
                Wendy Novianto
                [font=Verdana]PT DJAMOER Technology Media
                [font=Verdana]Xituz Media
                • 32241
                • 1,495 Posts
                Here is the list of current API list, I didn’t alter the comment at all, and I remove all deprecated function and the one from etomite.

                If I have time, I will put a mark of the one that had been explained in the documentation, so we all can work together in making the documentation for API that are still unknown.
                  Wendy Novianto
                  [font=Verdana]PT DJAMOER Technology Media
                  [font=Verdana]Xituz Media
                • Checks if the user has the specified "role" permission.
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 27526
                    • 204 Posts
                    Quote from: wendy at Jan 13, 2006, 09:36 PM

                    No problem Ryan. Hope my small contribution can help the community to grow even more.
                    Of course it does.
                    I’m not a coder at all, I just have algorythmie notions and your explanations ,illustraded by little exemples, look very clear to me. Good job, thanks a lot smiley.
                      • 32241
                      • 1,495 Posts
                      Quote from: Skopos at Jan 14, 2006, 08:33 AM

                      Of course it does.
                      I’m not a coder at all, I just have algorythmie notions and your explanations ,illustraded by little exemples, look very clear to me. Good job, thanks a lot smiley.

                      Thanks, that’s one encouraging word. Honestly, I suck as documentation, considering my english is not formal, and I have a habit of explaining thing to make people more confuse, instead to understand more. laugh
                        Wendy Novianto
                        [font=Verdana]PT DJAMOER Technology Media
                        [font=Verdana]Xituz Media