Skip to content
Snippets Groups Projects
Unverified Commit 9dba82e8 authored by Alice Frumin's avatar Alice Frumin Committed by GitHub
Browse files

buildAsset requires that the $asset varaible look like a file (containg a . )

parent d1456ac0
No related branches found
No related tags found
No related merge requests found
...@@ -176,7 +176,7 @@ In `myextension.php`: ...@@ -176,7 +176,7 @@ In `myextension.php`:
*/ */
function myextension_civicrm_buildAsset($asset, $params, &$mimetype, &$content) { function myextension_civicrm_buildAsset($asset, $params, &$mimetype, &$content) {
// Check for the asset of interest // Check for the asset of interest
if ($asset !== 'mycss') return; if ($asset !== 'mycss.css') return;
// Find the path to our template css file // Find the path to our template css file
$path = \Civi::resources()->getPath('org.example.myextension', 'css/my_css_template.css'); $path = \Civi::resources()->getPath('org.example.myextension', 'css/my_css_template.css');
...@@ -200,12 +200,12 @@ function myextension_civicrm_buildAsset($asset, $params, &$mimetype, &$content) ...@@ -200,12 +200,12 @@ function myextension_civicrm_buildAsset($asset, $params, &$mimetype, &$content)
Check it is functioning correctly: Check it is functioning correctly:
``` ```
$ cv ev '$x = \Civi::service("asset_builder")->render("mycss"); echo $x["content"];' $ cv ev '$x = \Civi::service("asset_builder")->render("mycss.css"); echo $x["content"];'
``` ```
Get the generated URL: Get the generated URL:
``` ```
$ cv ev 'return \Civi::service("asset_builder")->getUrl("mycss");' $ cv ev 'return \Civi::service("asset_builder")->getUrl("mycss.css");'
``` ```
Now we can use our newly defined asset in place of a static css file in `myextension.php`: Now we can use our newly defined asset in place of a static css file in `myextension.php`:
...@@ -220,8 +220,8 @@ function myextension_civicrm_coreResourceList(&$list, $region) { ...@@ -220,8 +220,8 @@ function myextension_civicrm_coreResourceList(&$list, $region) {
// CRM_Core_Resources::singleton()->addStyleFile('org.example.myextension', 'css/my_css.css'); // CRM_Core_Resources::singleton()->addStyleFile('org.example.myextension', 'css/my_css.css');
// replace that with the following: // replace that with the following:
// use the asset_builder service to get the url of an asset labeled 'mycss' // use the asset_builder service to get the url of an asset labeled 'mycss.css'
$url = \Civi::service('asset_builder')->getUrl('mycss'); $url = \Civi::service('asset_builder')->getUrl('mycss.css');
// load the processed style on the page // load the processed style on the page
CRM_Core_Resources::singleton()->addStyleUrl($url); CRM_Core_Resources::singleton()->addStyleUrl($url);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment