How to override Subscription Block at Drupal 8 Simplenews? - drupal-modules

I am developing a Drupal 8 website and I want to override the Subscription Block at Simplenews module. I know how to achieve that at Drupal 7, it's from simplenews-block.tpl.php , but the module is different now.
In Drupal-7 I used this to override the block instead of the .module file: http://api.worldempire.ch/api/simplenews/theme%21simplenews-block.tpl.php/7-2. ..I want the equivalent for Drupal-8.

There is no exact equivalent currently. To override the actual block template for that block you can use 'block--simplenewssubscription.html.twig'. You can use the input and form templates to override other elements. I would suggest enabling debugging in Twig so you can see the template overrides.

Related

Druplal view in twig is not rendered

new to drupal.
I have created a view called "my_view_2".
Inside my twig templates I use {{ my_view_2}} to render that view but nothing appears on the page.
If I declare the display of the view as page and assign a node to the view, then the view is rendered. But this way the node template is lost.
The above happens only to some views not very view I have and I can not find the differences between those that working and those that does not working.
any help is appreciated.
Looks like you want to create a view with some kind of display then use twig template to style it. If that's the case, then decide which twig template you want override and copy it over to your /theme folder.
Locate the template you wish to override.
Copy the template file from its base location into your theme folder.
(optionally) Rename the template according to the naming conventions in order to target a more specific subset of areas where the template is used.
Modify the template as you want.
With respect to views look at the below location for which template to copy/override :
core/themes/stable/templates/views/views-view.html.twig).
For example, if we want to override "views-view.html.twig" template for our view, the following template names are valid:
views-view--[viewid]--[view-display-id].html.twig
views-view--[viewid]--page.html.twig
views-view--block.html.twig
views-view--[viewid].html.twig
views-view.html.twig
Once you copy a template file into your theme and clear the cache, Drupal will start using your instance of the template file instead of the base version.
Reference:
Documentation:
https://www.drupal.org/docs/8/theming/twig/twig-template-naming-conventions
https://www.drupal.org/docs/8/theming/twig/working-with-twig-templates

How to show list content in Twig Drupal 8 without views

Sorry, I'm newbie in Drupal 8.
Is there any ways if we want to show content using Twig template in Drupal 8.
I have 2 kind of content let's say:
Article Content
Slider Content
I want to show them in front of my Drupal 8 page.
I see another suggestion is using views, but can I show them via Twig template?
Thanks for help.
Yes, you can. You have to create your own controller or custom plugin block to loads pages that you want and prints it in twig. Or you have to prepare your nodes variable using hook_preprocess_hook and then it will be able using twig.
doc #here

A way access field content with liquid

I am using the latest NuGet version of orchard core. As I want to use Bulma as CSS Framework, I Need to create tepmlates. One of several Problems that I have is: How can I Access the field contents from within a liquid template.
For instance the Blog theme has the content type Article. Within Article there is a field Subtitle. I created the template Article-TextField as
<h2 class="subtitle">{{ Model.Field.Text }}</h2>
The similar .cshtml template works, but apparently with a liquid template, there is no way to Access the TextField Text property. How can I do it the right way?
The problem is that the OrchardCore.ContentFields module doesn't register the TextField type with the Liquid's TemplateContext.GlobalMemberAccessStrategy service, which prevents you from accessing any members on the TextField object.
The module does register DisplayTextFieldViewModel like so:
TemplateContext.GlobalMemberAccessStrategy.Register<DisplayTextFieldViewModel>();
Not only is this unnecessary because the LiquidViewTemplate already registers the model automatically, it also doesn't help you much, since you can only access the model's Field property, but not its Text property.
For example, this will yield some output:
{{ Model }}
This will too:
{{ Model.Field }}
But as you correctly noticed, this won't:
{{ Model.Field.Text }}
This is clearly an omission in Orchard Core, specifically in the ContentFields module.
Since you're using the NuGet packages, you can't hack it into the source code obviously. But what you could do is add a Startup class to your theme that derives from StartupBase and add the following static constructor:
static Startup()
{
TemplateContext.GlobalMemberAccessStrategy.Register<TextField>();
}
Make sure to reference the OrchardCore.ContentFields NuGet package and import the OrchardCore.ContentFields.Fields namespace for your theme to compile.
After that, you will be able to access the Text property from your Liquid template.
Finally, I would recommend that you file an issue on GitHub about this omission so that you can ultimately remove the code I mentioned from your theme's Startup file.

Drupal 6 Availability of View Basic Settings Variables

I've been doing some basic view theming with Drupal 6, but I'm having a difficult time figuring out how to access certain variables. Here is my setup:
I have one view with several block displays.
I three templates I'm using to override the default:
views-view-unformatted-my-list-blocks.tpl.php (styles template)
views-view-my-list-blocks.tpl.php (rows template)
views-view-fields-my-list-blocks-block-1.tpl.php (an example display template)
Now, if I just copy the default code into the templates, everything seems to display as it should. But I noticed that in my styles template, the title variable is there, but nothing comes out. Even when I set my display title in basic settings, nothing shows. I would also like to access my CSS class variable from the basic settings, but I'm not sure what variable to use for that either.
Can anyone shed some light on these?
Here is an example on doing this
http://www.expresstut.com/content/themeing-views-drupal-6
http://www.expresstut.com/content/themeing-views-drupal-6-part-2

Use image buttons for pagination - Drupal

The default pagination in drupal is great, but the text links are used
<<first <previous 6 7 next> last>>
But I need to use forward and backward image buttons instead of text links. Can anyone point me in the right direction?
Depending on what portions of the pager you're interested in replacing with images, you may be able to use CSS background images, without having to override the theme function. However, in the default pager output, not all the links may have unique classes.
That said, if you're using Drupal's default pager, you can override the theme_pager function to add your image links.
If you're using the Views module, you may be using a different theming function. When in doubt, you should be able to use the Theme Developer module to find which function or template file is outputting the part of the page you're interested in theming. Theme Developer will also tell you what suggestions you can use to override the output.

Resources