Drupal 8 custom block output becoming blank after clearing cache - drupal-modules

I have created custom block in drupal 8 using custom module.
Assigned a twig template ( located in active theme ).
I am passing some custom theme_settings to twig template using theme_get_setting() method.
Everything works perfect.
But once i clear drupal cache, The variables i am passing to twig template are getting NULL values, and only static HTML is rendered, But same theme settings are populated correctly in drupal dashboard.

Related

Reading product metafields through Shopify ScriptTag API

I'm building a Shopify embedded application with two main points of functionality:
Upon install, product meta fields are populated with some values
Upon page load, a custom script is injected into product page through shopify ScriptTag api
The injected script displays some icon alongside the values from product meta fields.
Currently, from the product page, the injected script is having to request the meta fields from my local server, which then queries the clients shopify for before sending back the response.
Is there a way to access the meta field values directly from the product page, without having to do the above?
Thanks in advance.
The injected script only fires at page load on frontend, while accessing metafields is only possible via Liquid or Shopify API. The data flow that you have right now is the standard way of doing things in Shopify in such cases. However, considering performance implications or for whatever reasons, if you still want to achieve this, you can make use of Liquid.
Doing so can be done in 2 ways.
Provide a Liquid code snippet
Use Shopify API to add Liquid code snippet on App installation
Liquid Code Snippet
Once a user installs your app, provide them a Liquid code snippet to integrate in to their theme. That liquid code snippet should expose the Meta Fields to some JavaScript variable, that your injected script will read.
Shopify API to add Liquid code snippet
If you don't want the users to integrate the Liquid code snippet manually, then on Application install, make use of Theme Assets API to add you Liquid code snippet to the clients' active theme. This will need additional App permissions from users on install. Also factor in different available themes and removing code snippet from theme when App is uninstalled.
You haven't mentioned the resource where you will be creating metafields, but sample Liquid code snippet should look something like
<script>
var customMetaField = {shop.metafields.namespace.fieldname}
</script>
In your custom App script read the variable customMetaField. This is just a rough idea, you will need to check if the metafield namespace and the metafields exist and then output the values accordingly.
Shop Metafields

Yesod - Angular directive templates

How can I make a handler deliver HTML (using hamlet), whithout wrapping it inside defaultLayout?? They will have as root a div tag, not something inside a whole html tag. Such way should also consider internationalization.
Using Angular with Yesod works well because angular templating happens inside valid html that hamlet can generate.
Besides the current comment answer you might consider including a lot of templates using script tags inside a layout. I have done this before where there was a front page layout, an app layout, and an admin layout.

MVC5 how to make db calls for a layout page

I have a MVC5 app that is using layout page to control the header and footer ect. The layout page has some sections that are database driven such as the nav bar. I am not sure of the best practice for where to make these calls is. I can think of 2 ways but neither are perfect
Method 1: Pass in data with the pages view model. Don't like this approach has my homepage controller should only be concerned with homepage content, not the layout. This would have to be repeated for each and every view.
Method 2: Ajax to WebAPI controller. Kinda leaning towards this, although I think this means losing stuff like #URL and #HTML which are being used to create links and render custom content.
EDIT: Though of another method
Method 3: Load info into cache on Start. Since this is not info that changes often after initial setup and this code is displayed on every page, caching would be needed anyways.
You should call a controller method from within the view. On your view:
#Html.Action("MyAction", "MyController")
Make sure this action can find everything it needs without having to have values passed in, and you're set. We do this in several projects via service location and/or dependency injection.

Liferay model listener ordering

Following is my requirement :
Whenever site is created, with help of GroupListener we are adding some custom attributes to created site.
So assume that you are crating "Liferay Test" site then it will have some fix custom attribute "XYZ" with value set in GroupListeners onAfterCreate method.
I can see this value in custom fields under site settings.
Now based on this values, we are creating groups in another system(out of liferay, using webservices).
So far so good.
Whenever we are deleting the site we need to remove the equivalent groups from other system via web service.
But while deleting site, in GroupListener we are not able to retrieve the custom attributes.
On further debug by adding expando listener, I observed that Expando listeners are getting called first and then delete method of GroupLocalService/GroupListener.
And hence we are not able to delete the groups present in another system.
So I was wondering if we can have ordering defined for listeneres.
Note: Since we were not getting custom attributes in listeners we implemented GroupLocalServiceImpl and with this we are getting custom attributes in delete method on local environment but not on our stage environment which has clustering.
You shouldn't use the ModelListeners for this kind of change, rather create ServiceWrappers, e.g. wrap the interesting methods in GroupLocalService (for creation as well as deletion).
This will also enable you to react to failures to create records in your external system etc.

Server-side includes in expressjs

Is it possible to generate Server side includes with express.js?
I'm trying to reuse my header and footer markup on different pages so I can make header/footer changes in one place.
Try to use partials.
You have to choose between some template engines. The default template engine is jade, so for this you have to do the following: create a file views/header.jade and put your stuff in. in your action you can render the partial with partial('header');
See the expressjs docs for more.

Resources