I am trying to set a parent slug but it is somhow not working.
Following is my component.
public function componentDetails()
{
return [
'name' => 'SingleProject Component',
'description' => 'Get a single Project by slug'
];
}
/**
* @link https://docs.octobercms.com/3.x/element/inspector-types.html
*/
public function defineProperties()
{
return [
'slug' => [
'type' => 'string',
'title' => 'Slug',
],
'parentSlug' => [
'type' => 'string',
'title' => 'ParentSlug'
]
];
}
public function loadProject()
{
$query= PortfolioItems::where('slug', $this->property('slug'))->first();
return $query;
}
public function getParentSLug(){
// this will return a string like "project"
return Settings::instance()->getAttributeTranslated('portfolio_slug');
}
public function onRun()
{
$this->project = $this->loadProject();
$this->parent = $this->getParentSLug();
}
in the layout i am soing somthing like
url = "/:parentSlug/:slug"
layout = "default"
title = "New page"
[project]
slug = ":slug"
parentSlug = "project" => this place need to be from the component
==
{% component 'project' %}
I want to have a structure like
domain.tld/{parentSlug}/{slug}
i already tried
parentSlug = “{{ parent }}”
I am striving about this and any help would be really appreciated.
Actually what i am trying to do is pass a parameter from model to viewBag. what we are doing now is passing parameter from viewBag to Model/Twig. i want to have something in reverse order. from model to viewBag.
in this case the parentSlug parameter is from model.
what you think can be the possible way to achieve it.
I want to make the parentSlug dynamic.
if you look into wordpress they already have this functionaltiy to define a predefined parent slug for some post types. i want to achieve same thing but sa far i am not able to do it.
so you are looking at it the wrong way.
You are talking about the url generated before you reach that page which will be something like this in twig
[myComponent]
==
{% set parentSlug = myComponent. getParentSLug %} {# myComponent PHP code returns the value parentSlug from your function #}
<a href="{{ 'my_page' | page({ parentSlug: parentSlug , slug: project.slug} ) }} ">my link with dynamic parentSlug</a>
then your page is like @daftspunky mentioned earlier. And your second component will be able to read the parentSlug and the slug property.