Skip to content

Instantly share code, notes, and snippets.

View alasvant's full-sized avatar

Antti Alasvuo alasvant

View GitHub Profile
@alasvant
alasvant / HideContentTypesInitialization.cs
Created December 7, 2018 10:35
Sample code, Episerver initialization module to hide content types which you don't own.
using System;
using EPiServer.DataAbstraction;
using EPiServer.Framework;
using EPiServer.Framework.Initialization;
using EPiServer.Logging;
namespace AlloyWithFind.Business.Initialization
{
[InitializableModule]
[ModuleDependency(typeof(EPiServer.Web.InitializationModule), typeof(EPiServer.Forms.InitializationModule))]
@alasvant
alasvant / ExtendedTinyMceInitializationSample.cs
Created December 22, 2018 19:48
Sample TinyMCE configuration for a blog post. Cache bust style.css for editors.
using AlloyWithFind.Models.Blocks;
using AlloyWithFind.Models.Pages;
using EPiServer.Cms.TinyMce.Core;
using EPiServer.Framework;
using EPiServer.Framework.Initialization;
using EPiServer.ServiceLocation;
namespace AlloyWithFind.Business.Initialization
{
[ModuleDependency(typeof(TinyMceInitialization))]
@alasvant
alasvant / TinyMceTexts.xml
Created December 22, 2018 19:54
Sample TinyMCE editor custom styles localization in Episerver.
<?xml version="1.0" encoding="utf-8" ?>
<languages>
<language name="English" id="en">
<tinymce>
<editorstyles>
<title-paragraph-styles>Paragraph styles</title-paragraph-styles>
<title-introduction>Introduction</title-introduction>
<title-ingress>Ingress</title-ingress>
</editorstyles>
</tinymce>
@alasvant
alasvant / TagManagerElementBlock.cs
Last active February 23, 2019 13:03
Sample Google Tag Manager Episerver Forms element block.
using AlloyWithFind.Business.SelectionFactories;
using EPiServer.DataAbstraction;
using EPiServer.DataAnnotations;
using EPiServer.Forms.Core;
using EPiServer.Forms.Core.Internal;
using EPiServer.Forms.EditView;
using EPiServer.Shell.ObjectEditing;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
@alasvant
alasvant / GtmCategorySelectionFactory.cs
Created February 23, 2019 13:05
Sample GTM selection factory to pre-populate category selection options (Episerver Forms demo).
using EPiServer.Shell.ObjectEditing;
using System.Collections.Generic;
namespace AlloyWithFind.Business.SelectionFactories
{
/// <summary>
/// Selection factory to return GTM category values for form submission event.
/// </summary>
public class GtmCategorySelectionFactory : ISelectionFactory
{
@alasvant
alasvant / TagManagerElementBlock.cshtml
Created February 23, 2019 13:07
Sample view to render the TagManagerElementBlock.cs values for editors in edit mode and hidden input fields in the form.
@using EPiServer.Forms.EditView
@using EPiServer.Editor
@model AlloyWithFind.Models.FormElements.TagManagerElementBlock
@* if in edit mode render the GTM values so that the editor can see them *@
@if (PageEditing.PageIsInEditMode)
{
<span class="Form__Element FormHidden @Html.Raw(ConstantsFormsUI.CSS_InvisibleElement)">@Model.EditViewFriendlyTitle</span>
}
else
@alasvant
alasvant / gtm-submission.js
Created February 23, 2019 13:09
Sample JavaScript to set GTM dataLayer values (Episerver Forms demo).
if (typeof $$epiforms !== 'undefined') {
$$epiforms(document).ready(function myfunction() {
$$epiforms(".EPiServerForms").on("formsSubmitted", function (event) {
if (event.isFinalizedSubmission && event.isSuccess) {
// we have our custom dataLayer object, we could also have this code somewhere: window.dataLayer = window.dataLayer || []; and then use that
if (typeof dataLayer !== 'undefined') {
var currentForm = $$epiforms(this).get(0);
var categoryName = currentForm.elements["gtmCategoryName"].value;
var formName = currentForm.elements["gtmFormName"].value;
@alasvant
alasvant / SiteFormsContainerBlock.cs
Created March 24, 2019 14:34
Sample code for creating custom Episerver Forms form container block. This is the code part for the container block.
using EPiServer.DataAbstraction;
using EPiServer.DataAnnotations;
using EPiServer.Forms.Core;
using EPiServer.Forms.Implementation.Elements;
using EPiServer.ServiceLocation;
using System.ComponentModel.DataAnnotations;
namespace SampleCustomFormContainer.Models.Forms
{
[ServiceConfiguration(typeof(IFormContainerBlock))]
@alasvant
alasvant / SiteFormsContainerBlockController.cs
Created March 24, 2019 14:36
Sample code for creating custom Episerver Forms form container block. This is the controller code part.
using EPiServer.Forms.Controllers;
using EPiServer.Forms.Implementation.Elements;
using System.Web.Mvc;
namespace SampleCustomFormContainer.Controllers
{
public class SiteFormsContainerBlockController : FormContainerBlockController
{
public override ActionResult Index(FormContainerBlock currentBlock)
{
@alasvant
alasvant / FormContainerBlock.ascx
Last active March 24, 2019 14:37
Sample code for creating custom Episerver Forms form container block. This is the view file for the block. This code is copy paste from the Episerver Forms container block code. Only custom property rendering is added to the original code.
<%--
====================================
Version: 4.9.1. Modified: 20171030
====================================
--%>
<%@ Import Namespace="System.Web.Mvc" %>
<%@ Import Namespace="EPiServer.Web.Mvc.Html" %>
<%@ Import Namespace="EPiServer.Shell.Web.Mvc.Html" %>
<%@ Import Namespace="EPiServer.Forms" %>