I am stuck in my custom code.
I want to pass a custom variable from email template to pthml file.
Edit file
app/code/local/Mage/Sales/Model/Order.php
in this function :
public function sendNewOrderEmail()
{
--- default code start ----
$mailer->setTemplateParams(array(
'order' => $this,
'test' => 'XXXXX',
'billing' => $this->getBillingAddress(),
'payment_html' => $paymentBlockHtml
)
);
--- default code end ----
}
and then I put this code in New Order email template:
{{layout handle="sales_email_order_items" order=$order test=$test}}
template file located here :
app/locale/en_US/template/email/sales/order_new.html
and I am trying to get test variable Here:
app/design/frontend/default/default/template/email/order/items/order/default.phtml
like this: $test = $this->getItem()->getTest()
but not get success. Please let me know where am I wrong? or what to do need to access this variable in phtml file?
Your problem here is that the 'test' value goes to the main block Mage_Sales_Block_Order_Email_Items that uses "email/order/items.phtml" tempalte.
In there you can find the data using:
<?php $test = $this->getTest(); // or $this->getData('test') ?>
You can then add this data into a registry.
But a better way is to send set this info onto the order items before the email.
So, in email function before $mailer->setTemplateParams(); add a code like:
//$this = current order if you are in Mage_Sales_Model_Order
foreach ($this->getAllVisibleItems() as $item) {
$item->setData('test', 'test_value_10');
}
To get variable in your email template
{{var test}}
Take a look # Defining Transactional Variables
Related
I'm trying to pass a varible from the Controller to my .blade.php file.
I'm returning the view and compacted variables to the .blade.php but it doens't recognize the
variable.
This is the code of the Controller.
$contents = Storage::get($request->file('csv_file_1')->store('temporaryfiles'));
$contents2 = Storage::get($request->file('csv_file_2')->store('temporaryfiles'));
return view('comparison.comparison')->with(compact('contents'),$contents)->with(compact('contents2'),$contents2);
And i'm trying every way just to get an result but instead i'm getting the "Undefined variable $contents" page. The last method i used was a simple
<p>{{$contents}}</p>
I don't think it's correct but i don't really remember how to do it.
In controller return like:
return view('comparison.comparison', compact(['contents', 'contents2']);
And make sure your file is in resources/views/comparison/comparison.blade.php
Try this
$contents = Storage::get($request->file('csv_file_1')->store('temporaryfiles'));
$contents2 = Storage::get($request->file('csv_file_2')->store('temporaryfiles'));
return view('comparison.comparison', compact('contents','contents2'));
if you have defined a veriable above just use tha name inside compact as above and it can be acced inside blade as <p>{{$contents}}</p>
You can pass variables like that it's not mandatory to use compact.
return view('comparison.comparison', [
'contents' => $contents,
'contents2' => $contents2
]);
or if you want with compact:
return view('comparison.comparison')->with(compact('contents', 'contents1'));
I’ve added a file inside App/icons/icons.php which has an array
<?php
$skills_icon = array(
‘one’,
‘two’,
‘three’
);
I have added the icons.php file in functions.php
array_map(function ($file) use ($sage_error) {
$file = "../app/{$file}.php";
if (!locate_template($file, true, true)) {
$sage_error(sprintf(__('Error locating <code>%s</code> for inclusion.', 'sage'), $file), 'File not found');
}
}, ['icons/icons','helpers', 'customizers/intro', 'customizers/skills', 'widgets/skills']);
and in my views home.blade.php I want to recieve array values values from it.
{{ var_dump($skills_icon)}}
But im receiving NULL values.
Anything I'm missing?
If you are sure that your file is loaded, have you try putting your data in a method that returns the data, and then call this method?
You could also add your file as a config/file.php, by adding it at the end of the function.php file with the others. And then call it with config() helper normally.
I wonder if I can get the View name based on full path of the view file.
Code example (expectation code):
$full_path = "D:\laragon\www\my-laravel-app\resources\views\user\login.blade.php";
$view_name = get_view_name($full_path);
echo $view_name;
// My expectation result should be $view_name = "user.login";
//
// So, it should echo this ---> user.login
Can I achieve this?
Thanks
I just got a solution.
function get_view_name($full_path){
$view_root_path = config('view.paths')[0];
$view_name = strtr($full_path, [
$view_root_path.'/' => '',
'.blade.php' => '',
'/' => '.',
]);
return $view_name;
}
But I think this is quite dirty solution.
So, I still hope if someone else got better and clean solution.
Thanks.
You can get name of route by using this
$request->route()->getName();
Or if you don't have $request where you want name of route you can achieve this with Request class
use Illuminate\Http\Request
Request::route()->getName();
That later different languages can be used, i would like want to save status and success messages in a central file and output them by the respective controller. Currently I'm still doing that in each controller extra.
At the moment:
return back()->with('status', 'Thanks for contacting us!');
Manually insert all the messages in directory resources > lang > en > messages.php , or create any other language folder you might want.
And then you can use it with this Lang::get('messages.success');
*use this in your controller use Illuminate\Support\Facades\Lang;
In your case like this: return back()->with('status', Lang::get('messages.success'));
An example of messages.php would be:
return [
'success' => 'your success message.',
'success1' => 'your success1 message.'
];
I'm a noob in the modx world. I have a page with subpages and I using getResources to display the content of those in tabs on the parent page.
What I would like to do is only display that chunk if the parent has subpages?
So something like this, but this is obviously not right because its not working.
[[!getResources &parent:notempty=`[[$chunk]]`]]
Give this a shot, create a new snippet for this;
<?php
// get the current resource id
$id = $modx->resource->get('id');
// get the resource object
$resource = $modx->getObject('modResource', $docId);
// make sure we have a resource
if($resource){
// see if the resource has children
$hasChildren = $resource->hasChildren();
if($hasChildren){ // pretty sure hasChildren returns 1 or 0
// optionally, retrieve the chunk & populate it.
// replace your-chunk-name and the placeholders with your values.
$output = $modx->getChunk('your-chunk-name',array(
'placeholder-1-name' => 'value',
'placeholder-2-name' => 'value',
'placeholder-3-name' => 'value',
'placeholder-4-name' => 'value',
));
return $output;
}
}
return true;
it's &parents , with "s".
Anyway,
If you want to use output filter for snippet, you add it BEFORE the question mark:
[[!getResources:isempty=`No content is available`? &parents =`[[*id]]`]]