Hello, I was actually trying to figure this out in Sage 10 and came across this thread. I noticed no one has posted an answer to your question so I will share my discovery. The following worked for me, given your example:
echo \Roots\view('path.to.your.template.icon', ['yourTargetParam', 'chevron-left'])->render();
I can’t really give you an exact answer since I don’t know the paths and params for your component. As a result, I will give you a full example that I am working with:
In [theme]/app/View/Components/FieldsSectionTitle
I have defined my component class with:
<?php
namespace App\View\Components;
use Roots\Acorn\View\Component;
/**
* Fields Section Title
*
* Common section title component with a bar above title text which is used
* in A LOT of custom mfj blocks.
*/
class FieldsSectionTitle extends Component {
/**
* Title
*
* @var string
*/
public $title;
/**
* Title Text Alignment Attr Class
*
* @var string
*/
public $textAlignAttrClass;
/**
* Title Bar Style
*
* The bootstrap background css attribute used to set the
* title's bar color.
*
* @var string
*/
public $titleBarStyle;
/**
* Title Attr Classes
*
* @var string
*/
public $titleAttrClasses;
/**
* Title Bar Attr Classes
*
* CSS Selector classes to add to the "title bar" css attribute.
*
* @var string
*/
public $titleBarAttrClasses;
/**
* Create the component instance.
*
* @param string $title Title text string
* @param string $textAlignAttrClass Title alignment css selector class
* @param string $titleBarStyle Title bar background color bootstrap selector class
* @param string $titleAttrClasses Title css selector classes
* @param string $titleBarAttrClasses Title bar selector css classes
*/
public function __construct(
string $title = '',
string $textAlignAttrClass = '',
string $titleBarStyle = '',
string $titleAttrClasses = '',
string $titleBarAttrClasses = ''
) {
$this->title = $title;
$this->textAlignAttrClass = $textAlignAttrClass;
$this->titleBarStyle = $titleBarStyle;
$this->titleAttrClasses = $titleAttrClasses;
$this->titleBarAttrClasses = $titleBarAttrClasses;
}
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\View\View|string
*/
public function render() {
return $this->view('components.fields-section-title');
}
}
Now, I can do the following to pass my params to the component view from OUTSIDE of my sage 10 app directory. In my case, I am overwriting plugin page templates that need to live outside of the app directory:
echo \Roots\view('components.fields-section-title', [
'title' => 'Testing',
'titleBarStyle' => Constants::BOOTSTRAP_BG_BLUE_MD
])->render();
One thing to note here is, if you want all component parameters to be optional in the above example usage… then you need to do safety checks in your component’s blade template. Otherwise, you will get missing $var errors because using the Roots view renderer bypasses the component’s class model logic:
$title = !empty($title) ? $title : '';
$textAlignAttrClass = !empty($textAlignAttrClass) ? $textAlignAttrClass : '';
$titleBarStyle = !empty($titleBarStyle) ? $titleBarStyle : '';
$titleAttrClasses = !empty($titleAttrClasses) ? $titleAttrClasses : '';
$titleBarAttrClasses = !empty($titleBarAttrClasses) ? $titleBarAttrClasses : '';
Hopes this helps people in the future!