8 – Custom form returns NULL in custom template

I have a couple things:

-A custom form

-A custom theme

-A custom module for this form

I am trying to get the custom form to display on a custom template which is in a custom theme.

structure for custom module called weeks:

weeks

-src

–Controller

—WeeksController.php

–Form

—FormWeeks.php

-weeks.info.yml

-weeks.install

-weeks.module

-weeks.routing.yml

this is what FormWeeks.php looks like

<?php

namespace DrupalweeksForm;
use DrupalCoreFormFormBase;
use DrupalCoreFormFormStateInterface;

class WeeksForm extends FormBase {
  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'weeks_form';
  }

  public function buildForm(array $form, FormStateInterface $form_state) {
    
    
    $form('#theme') = 'weeks_form';
    
    
    $form('deactivate') = array(
        '#type' => 'submit',
        '#value' => $this->t('Deactivate'),
        '#name' => 'deactivate',
    );
    $form('2_week_pause') = array(
    '#type' => 'submit',
    '#value' => $this->t('Pause for 2 weeks'),
    '#name' => 'pause'
    );
    $form('start_again_week_1') = array(
    '#type' => 'submit',
    '#title' => $this->t('Start again at week 1'),
    '#name' => 'restart_week_1',
    );
 
    return $form;
  }

   /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    

     $action = $form_state->getTriggeringElement()('#name');
     $user = Drupal::currentUser();
     if($action == 'deactivate'){
        $user->set('field_52_weeks', $action);
        $user->save();
     }else if ($action == 'restart_week_1'){
        $user->set('field_current_week', 1);
        $user->save();
     } else if ($action == '2_week_pause'){
        $user->set('field_52_weeks', $action);
        $user->save();
     }
    }

    
  
}

This is what is in weeks.module

<?php
function weeks_theme($existing, $type, $theme, $path){
   
    
    return (
        'weeks_form' => (
            'render element' => 'form',
            'template' => 'html--52weeks',
            
        )
    );
    }
    

this is what weeks.routing.yml looks like

weeks.page:
  path: '/52weeks'
  defaults:
    _title: '52 weeks'
    _form: 'DrupalweeksFormWeeksForm'
  requirements:
    _permission: 'access content'


I have a twig file in themes/custom/mytheme/templates called html–52weeks.html.twig. This is whats in there:

{{ dump(form) }}

that ^^ returns null and I have no idea why. I’ve tried changing the $form(‘#theme’) = ‘mytheme’, in WeekForm.php, but this still doesnt work. What I want is for this form to be displayed when someone goes to the /52weeks url. The main problem is that the form does not get passed to the template

PHP wordpress – template part including not working

EDIT –

I have since tried a blank and new php file and accessing it the same way – that worked. So I am now unclear why the existing file does not load at all. There are no errors.

I am trying to include a partial template and have read up on how to do so.

<div class="row">
    <div class="col-md-12">
        <?php get_template_part('/partials/category.php');
        ?>
    </div>
</div> 

The file I have included the above code in is in the theme main. The partial is in a folder in the theme main called partials. When I use /partials/category.php I get a blank with no PHP error in the area of the page where the information should be.

If I dont use the / on front of partials I get an error.

I have also tried removing the / on the front and at the same time removing the .php at the end. Same result where there is no error and no output

What am I missing about getting the template part to display>?

views – Template suggestion does not work for table in a custom block / Might there be a way around?

I created a block on pages of the “Author” content type that lists all the articles the author has contributed to in a table (via contextual filter). Now I want to customize the table layout. I already did this before in a similar case, where I show the table on a page, not in a block. There I get file name suggestions for the template inside HTML comments like that:

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'views_view_table__articles' -->
<!-- FILE NAME SUGGESTIONS:
   x views-view-table--articles.html.twig
   x views-view-table--articles.html.twig
   * views-view-table.html.twig
-->
<!-- BEGIN OUTPUT from 'themes/MYTHEMEFOLDER/templates/views/views-view-table--articles.html.twig' -->

But in my latest case, the table in a block, I only get this suggestion:

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'views_view_table' -->
<!-- BEGIN OUTPUT from 'themes/MYPARENTTHEMEFOLDER/templates/views/views-view-table.html.twig' -->

Note that it outputs the template of my parent theme, not my actual theme.

I did some research and found this issue, which currently is not resolved and the proposed patch not included inside the Drupal code. Is this the reason I cannot create a custom template or is there something else I can do?

If not, how would I create that table of referenced articles on the author’s page?

Sharepoint Display Template – SharePoint Stack Exchange

I created a display template in SharePoint server 2019. But I don’t see the template in the template list.
My site collection is SharePoint publishing feature enabled. I observed one thing, after the template creation there should be a javascript file with same name of the template, but there is no javascript file created with the same name. Need help.
Thank you in advance.

Sincerely
Farook Golam

theme development – How to create code template to promote products inside WordPress post

I want to suggest products inside a post content, something similar to the wirecutter style, but I don’t how to get started without using a plugin.
Does anyone have any idea what would be the best approach to get this done?
The product promotion has to include product name, subtitle, description, image, and button with the link to the product.

javascript – Sharepoint 2019 – modify search result item template to return Office URI Schemes

I am looking for a way to open word, excel, ppt files in a local client application.
For any mysterious reasons that work in document libraries but not in search results.
I know that it works if I manually add the micrsoft URI sheme to a file-URL.

So my idea was to modify the search result item template (HoverPanel) output from the “open”-link. So that the “open”-Link does return the Microsoft Uri schema instead of the plain file-URL.
The reason why I choose this way is to avoid client-side javascript code like in cewp or script-editor-webpart.

I am definitely no javascript professional, so maybe anybody can tell me whether that is possible or not. And of course, if it’s possible, a code example would be very nice ^_^

Below the example content of Item_powerPoint.html and Item_PowerPoint_HoverPanel.html.

Item_PowerPoint.html

<html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"> 
<head>
<title>PowerPoint-Element</title>
<!--(if gte mso 9)><xml>
<mso:CustomDocumentProperties>
<mso:TemplateHidden msdt:dt="string">0</mso:TemplateHidden>
<mso:MasterPageDescription msdt:dt="string">Zeigt ein auf Microsoft PowerPoint-Dokumente abgestimmtes Ergebnis an.</mso:MasterPageDescription>
<mso:ContentTypeId msdt:dt="string">0x0101002039C03B61C64EC4A04F5361F385106603</mso:ContentTypeId>
<mso:TargetControlType msdt:dt="string">;#SearchResults;#</mso:TargetControlType>
<mso:HtmlDesignAssociated msdt:dt="string">1</mso:HtmlDesignAssociated>
<mso:ManagedPropertyMapping msdt:dt="string">'Title':'Title','Path':'Path','Description':'Description','EditorOWSUSER':'EditorOWSUSER','LastModifiedTime':'LastModifiedTime','CollapsingStatus':'CollapsingStatus','DocId':'DocId','HitHighlightedSummary':'HitHighlightedSummary','HitHighlightedProperties':'HitHighlightedProperties','FileExtension':'FileExtension','ViewsLifeTime':'ViewsLifeTime','ParentLink':'ParentLink','FileType':'FileType','IsContainer':'IsContainer','SecondaryFileExtension':'SecondaryFileExtension','DisplayAuthor':'DisplayAuthor','ServerRedirectedURL':'ServerRedirectedURL','SectionNames':'SectionNames','SectionIndexes':'SectionIndexes','ServerRedirectedEmbedURL':'ServerRedirectedEmbedURL','ServerRedirectedPreviewURL':'ServerRedirectedPreviewURL'</mso:ManagedPropertyMapping>
</mso:CustomDocumentProperties>
</xml><!(endif)-->
</head>
<body>
    <div id="Item_PowerPoint">
<!--#_ 
        if(!$isNull(ctx.CurrentItem) && !$isNull(ctx.ClientControl)){
            var id = ctx.ClientControl.get_nextUniqueId();
            var itemId = id + Srch.U.Ids.item;
            var hoverId = id + Srch.U.Ids.hover;
            var hoverUrl = "~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_PowerPoint_HoverPanel.js";
            $setResultItem(itemId, ctx.CurrentItem);
            ctx.currentItem_ShowHoverPanelCallback = Srch.U.getShowHoverPanelCallback(itemId, hoverId, hoverUrl);
            ctx.currentItem_HideHoverPanelCallback = Srch.U.getHideHoverPanelCallback();
            ctx.CurrentItem.csr_OpenApp = "powerpoint";
_#-->
            <div id="_#= $htmlEncode(itemId) =#_" name="Item" data-displaytemplate="PowerPointItem" class="ms-srch-item" onmouseover="_#= ctx.currentItem_ShowHoverPanelCallback =#_" onmouseout="_#= ctx.currentItem_HideHoverPanelCallback =#_">
<!--#_
                if(!$isNull(ctx.CurrentItem.ServerRedirectedPreviewURL))
                {
                    ctx.CurrentItem.csr_PreviewImage = ctx.CurrentItem.ServerRedirectedPreviewURL;
                    ctx.CurrentItem.csr_PathLength = Srch.U.pathTruncationLengthWithPreview;
                }
                ctx.CurrentItem.csr_Icon = Srch.U.getIconUrlByFileExtension(ctx.CurrentItem);
_#-->
                _#=ctx.RenderBody(ctx)=#_
                <div id="_#= $htmlEncode(hoverId) =#_" class="ms-srch-hover-outerContainer"></div>
            </div>
<!--#_
        }
_#-->
    </div>
</body>
</html>

Item_PowerPoint_HoverPanel.html

<html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"> 
<head>
<title>PowerPoint-Daraufzeigebereich</title>

<!--(if gte mso 9)><xml>
<mso:CustomDocumentProperties>
<mso:TemplateHidden msdt:dt="string">0</mso:TemplateHidden>
<mso:MasterPageDescription msdt:dt="string">Zeigt einen auf Microsoft PowerPoint-Dokumente abgestimmten Ergebnisdaraufzeigebereich an.</mso:MasterPageDescription>
<mso:ContentTypeId msdt:dt="string">0x0101002039C03B61C64EC4A04F5361F385106603</mso:ContentTypeId>
<mso:TargetControlType msdt:dt="string">;#SearchHoverPanel;#</mso:TargetControlType>
<mso:HtmlDesignAssociated msdt:dt="string">1</mso:HtmlDesignAssociated>
<mso:ManagedPropertyMapping msdt:dt="string">'Title':'Title','Path':'Path','Description':'Description','EditorOWSUSER':'EditorOWSUSER','LastModifiedTime':'LastModifiedTime','CollapsingStatus':'CollapsingStatus','DocId':'DocId','HitHighlightedSummary':'HitHighlightedSummary','HitHighlightedProperties':'HitHighlightedProperties','FileExtension':'FileExtension','ViewsLifeTime':'ViewsLifeTime','ParentLink':'ParentLink','FileType':'FileType','IsContainer':'IsContainer','SecondaryFileExtension':'SecondaryFileExtension','DisplayAuthor':'DisplayAuthor','ServerRedirectedURL':'ServerRedirectedURL','SectionNames':'SectionNames','SectionIndexes':'SectionIndexes','ServerRedirectedEmbedURL':'ServerRedirectedEmbedURL','ServerRedirectedPreviewURL':'ServerRedirectedPreviewURL'</mso:ManagedPropertyMapping>
</mso:CustomDocumentProperties>
</xml><!(endif)-->
</head>
<body>
    <div id="Item_PowerPoint_HoverPanel">
<!--#_
        var i = 0;
        var wacurlExist = !Srch.U.e(ctx.CurrentItem.ServerRedirectedURL) && !Srch.U.e(ctx.CurrentItem.ServerRedirectedEmbedURL);
        var id = ctx.CurrentItem.csr_id;
        ctx.CurrentItem.csr_FileType = Srch.Res.file_PowerPoint;
        ctx.CurrentItem.csr_ShowFollowLink = true;
        ctx.CurrentItem.csr_ShowViewLibrary = true;
        ctx.currentItem_IsOfficeDocument = true;
_#-->
        <div class="ms-srch-hover-innerContainer ms-srch-hover-wacSize" id="_#= $htmlEncode(id + HP.ids.inner) =#_">
            <div class="ms-srch-hover-arrowBorder" id="_#= $htmlEncode(id + HP.ids.arrowBorder) =#_"></div>
            <div class="ms-srch-hover-arrow" id="_#= $htmlEncode(id + HP.ids.arrow) =#_"></div>
            <div class="ms-srch-hover-content" id="_#= $htmlEncode(id + HP.ids.content) =#_" data-displaytemplate="PowerPointHoverPanel">
                <div id="_#= $htmlEncode(id + HP.ids.header) =#_" class="ms-srch-hover-header">
                    _#= ctx.RenderHeader(ctx) =#_
                </div>
                <div id="_#= $htmlEncode(id + HP.ids.body) =#_" class="ms-srch-hover-body">
<!--#_
                    if(!Srch.U.n(ctx.CurrentItem.ServerRedirectedEmbedURL))
                    {
                        ctx.CurrentItem.csr_DataShown = true;
                        ctx.currentItem_ShowChangedBySnippet = true;
_#-->
                        <div class="ms-srch-hover-viewerContainer">
                            <iframe id="_#= $htmlEncode(id + HP.ids.viewer) =#_" src="https://sharepoint.stackexchange.com/_#= $urlHtmlEncodeString(ctx.CurrentItem.ServerRedirectedEmbedURL) =#_" scrolling="no" frameborder="0px" class="ms-srch-hover-viewer"></iframe>
                        </div>
                        <div class="ms-srch-hover-wacImageContainer">
                            <img id="_#= $htmlEncode(id + HP.ids.preview) =#_" alt="_#= $htmlEncode(Srch.Res.item_Alt_Preview) =#_" onload="this.parentNode.style.display='block';" />
                        </div>
<!--#_
                    }
                    else
                    {
                        ctx.CurrentItem.csr_ShowLastModifiedTime = true;
                        ctx.CurrentItem.csr_ShowAuthors = true; 
                    }

                    if(!Srch.U.e(ctx.CurrentItem.SectionNames))
                    {
                        ctx.CurrentItem.csr_DataShown = true;
_#-->
                        <div class="ms-srch-hover-subTitle"><h3 class="ms-soften">_#= $htmlEncode(Srch.Res.hp_SectionHeadings) =#_</h3></div>
<!--#_
                        var sectionNames = Srch.U.getArray(ctx.CurrentItem.SectionNames);

                        var sectionIndexes = Srch.U.getArray(ctx.CurrentItem.SectionIndexes);
                        if(!Srch.U.n(sectionIndexes) && sectionIndexes.length != sectionNames.length)
                        {
                            sectionIndexes = null;
                        }

                        var hitHighlightedSectionNames = Srch.U.getHighlightedProperty(id, ctx.CurrentItem, "sectionnames");
                        if(!Srch.U.n(hitHighlightedSectionNames) && hitHighlightedSectionNames.length != sectionNames.length)
                        {
                            hitHighlightedSectionNames = null;
                        }

                        var numberOfSectionsToDisplay = Math.min(Srch.SU.maxLinesForMultiValuedProperty, sectionNames.length);
                        var sectionsToDisplay = new Array();

                        var usingHitHighlightedSectionNames = Srch.SU.getSectionsForDisplay(
                            hitHighlightedSectionNames,
                            numberOfSectionsToDisplay,
                            sectionsToDisplay);

                        for(i = 0; i < sectionsToDisplay.length; ++i)
                        {
                            var index = sectionsToDisplay(i);
                            if(Srch.U.n(index))
                            {
                                continue;
                            }

                            var tooltipEncoded = $htmlEncode(sectionNames(index));

                            var htmlEncodedSectionName = "";
                            if(usingHitHighlightedSectionNames)
                            {
                                htmlEncodedSectionName = hitHighlightedSectionNames(index);
                            }
                            else
                            {
                                htmlEncodedSectionName = tooltipEncoded;
                            }
_#-->
                            <div class="ms-srch-hover-text ms-srch-ellipsis" id="_#= $htmlEncode(id + HP.ids.sectionName + i) =#_" title="_#= tooltipEncoded =#_">
<!--#_
                                if(!Srch.U.n(sectionIndexes) && sectionIndexes.length >= i && !Srch.U.e(sectionIndexes(index)) && wacurlExist)
                                {
                                    var encodedSlideIndex = "&wdSlideIndex=" + $urlKeyValueEncode(sectionIndexes(index));
_#-->
                                    <a clicktype="HoverSection" linkIndex="_#= $htmlEncode(i) =#_" href="_#= $urlHtmlEncodeString(ctx.CurrentItem.ServerRedirectedURL + encodedSlideIndex) =#_" target="_blank">
                                        _#= htmlEncodedSectionName =#_
                                    </a>
<!--#_
                                }
                                else
                                {
_#-->
                                    _#= htmlEncodedSectionName =#_
<!--#_
                                }
_#-->
                            </div>
<!--#_
                        }
                    }
_#-->
                    _#= ctx.RenderBody(ctx) =#_
                </div>
                <div id="_#= $htmlEncode(id + HP.ids.actions) =#_" class="ms-srch-hover-actions">
                    _#= ctx.RenderFooter(ctx) =#_
                </div>
            </div>
<!--#_
            if(!Srch.U.n(ctx.CurrentItem.ServerRedirectedEmbedURL)){
                AddPostRenderCallback(ctx, function(){
                    HP.loadViewer(ctx.CurrentItem.id, ctx.CurrentItem.id + HP.ids.inner, ctx.CurrentItem.id + HP.ids.viewer, ctx.CurrentItem.id + HP.ids.preview, ctx.CurrentItem.ServerRedirectedEmbedURL, ctx.CurrentItem.ServerRedirectedPreviewURL);
                });
            }
_#-->
        </div>
    </div>
</body>
</html>

sharepoint online – How to truncate string inside modern search template handlebars

You need to create a custom handlebar helper to truncate the string.

Example:

public registerHandlebarsCustomizations(namespace: typeof Handlebars) {
    namespace.registerHelper('trimString', function(passedString, startstring, endstring) {
        var theString = passedString.substring( startstring, endstring );
        return new namespace.SafeString(theString)
    });
}

Then, in template, you can use it like:

<p>{{{trimString value 0 50}}}</p>

References:

  1. Register Handlebars customizations
  2. Handlebars – substring

Users are saving over a fillable template and wrecking the original

We have a template that users need to modify and return as an attachment but they are modifying the original and saving it which then leaves their info for the next user. How do we stop this? They do need to complete the form (so it can’t be read only) – but not save back over the original.

Thanks in anticipation

theming – How to create template suggestion for image like IMAGE–BLOCK-TYPE or IMAGE–FIELD-TYPE

I’m struggling to make template suggestions like IMAGE–BLOCK-TYPE or IMAGE–FIELD-TYPE.
I have three different block types(image1, image2, image3) with one image field(field_image_1, field_image_2 and field_image_3).
And I don’t know how to get suggestion like

image–block_image1.html.twig

image–block_image2.html.twig

image–block_image3.html.twig

or

image–field_image_1.html.twig

image–field_image_2.html.twig

image–field_image_3.html.twig

my_theme_suggestions_image_alter(array &$suggestions, array $variables)
{

}

Please help!

8 – How can I reference an entity field in a template file?

I am trying to theme the node add/edit form for a custom content type (for example, Album). I implemented hook_form_alter() in the theme.

function mytheme_form_alter(&$form, DrupalCoreFormFormStateInterface $form_state, $form_id) {
  switch ($form_id) {
    case "node_album_form":
      $form('#theme') = ('node_album_edit_form');
      break;
  }
}

That correctly intercepts the node add/edit form and passes it to my theme hook which also finds the correct template.

function mytheme_theme() {
  return (
    'node_album_form' => (
      'template' => 'node_album_edit_form',
      'path' => Drupal::theme()->getActiveTheme()->getPath() . '/scss/templates/album',
      'render element' => 'form'
    ),
  );
}

In node_album_edit_form.html.twig, I can confirm that changes there alter only the album add/edit form and that I can remove elements with {{ form|without('advanced', 'footer', 'actions') }}, for example.

What I cannot do is placing the form fields where I want them because I’m not using the right reference to the field.

<div class='myfancydiv album-title-field'>{{ field_album_title }}</div>
<div class='myfancydiv album-artist-field'>{{ field_artist }}</div>

I tried any of the following, but they didn’t work.

  • {{ field_album_title }}
  • {{ form.field_album_title }}
  • {{ album_title }}

How can I reference an entity field in a template file?