RainLab\Pages\Classes\Snippet::initFromPartial PHP Method

initFromPartial() public method

Initializes the snippet from a CMS partial.
public initFromPartial ( $partial )
    public function initFromPartial($partial)
    {
        $viewBag = $partial->getViewBag();
        $this->code = $viewBag->property('snippetCode');
        $this->description = $partial->description;
        $this->name = $viewBag->property('snippetName');
        $this->properties = $viewBag->property('snippetProperties', []);
    }

Usage Example

Example #1
0
 /**
  * Returns a list of snippets in the specified theme.
  * @param \Cms\Classes\Theme $theme Specifies a parent theme.
  * @return array Returns an array of Snippet objects.
  */
 protected function listThemeSnippets($theme)
 {
     $result = [];
     $partials = Partial::listInTheme($theme, true);
     foreach ($partials as $partial) {
         $viewBag = $partial->getViewBag();
         if (strlen($viewBag->property('snippetCode'))) {
             $snippet = new Snippet();
             $snippet->initFromPartial($partial);
             $result[] = $snippet;
         }
     }
     return $result;
 }