Quick-include an article

I needed a small snippet to include tips in my document project. I had to have a dynamic way to include certain documents in multiple places with option to change the included documents - also the navigation access point or position in website if needed. Therefore GUID was the way.

Here's how I did it:

In style element <(show-article)> I changed

&(view["content"]:h);

to this:

<?php
  $content = $view["content"];
  
  while (ereg("[:]{2}guid-([[:alnum:]]{32})[:]{2}", $content, $include)) {
    $article = mgd_get_object_by_guid($include[1]);
    if ($article) {

      // Defining header and footer to content data
      $header = "
       <fieldset class=\"tip\">
        <legend>
         Tip - {$article->title}
         (<a href=\"/midcom-permalink-{$article->guid()}\"Permalink</a>)
        </legend>\n";
      $footer   = "</fieldset>\n";

      // Replacing the content
      $content = str_replace("::guid-".$include[1]."::", $header . $article->content . $footer, $content);
    } else {
      $content = str_replace("::guid-".$include[1]."::", "", $content);
    }
  }
?>
&(content:h);

This works if component schema has "content" and supports (at least) method $object->content.

After this you can include any article with GUID by simply entering ::guid-[32-characters GUID]:: in midst of content text.

Snippet can be found in action in help file of "widget" => "select".

Back