Accessing snippet properties in php code

Hello,

So glad to come across snippets, such a handy way to make static pages editable.

I have a problem I need help with, I tried searching the documentation but was unable to find anything like this, so posting here.

I have created a snippet from a partial, and called that snippet on a a static page and it is working as expected. However, what I am trying to do now is load some content form the database so that the snippet shows data according to the property value passed to it. but I am not sure how to access the property value inside the PHP code block.

I can access the property value from within the twig code, but not php. any help will be appreciated! thankyou.

Hello @tasaduqbahl ,

you can register your plugin’s components to be used as Snippets in your Plugin.php file,

public function registerPageSnippets()
    {
        return [
            \Acme\Plugin\Components\MyComponent::class => 'my-component'
        ];
    }

it will herit your component properties which are define in your /components/MyComponent.php file

    public function defineProperties()
    {
        return [
            ...                
            ]
        ];
    }

More information here : Snippets - October CMS - 3.x

I am not using component, I am using a partial. So therefore there is no plugin.php

It was as simple as $this->property_slug

I am so surprised this was not part of the documentation anywhere.