Brand Your Community Using Less and Gulp

41
Brand Your Community Using Less and Gulp Shuji Ui Senior Technical Architect, 7summits [email protected] Twitter @shujiui

Transcript of Brand Your Community Using Less and Gulp

Page 1: Brand Your Community Using Less and Gulp

Brand Your Community Using Less and Gulp

 Shuji Ui  Senior Technical Architect, 7summits  [email protected]  Twitter @shujiui  

Page 2: Brand Your Community Using Less and Gulp

Shuji Ui Senior Technical Architect

7summits

Page 3: Brand Your Community Using Less and Gulp

•  How many people built Community sites using Community cloud?

•  How many people have used Salesforce Tabs + Visualforce Community template?

•  How many people have used Less?

•  How many people have used Gulp?

Have you used Community Cloud?

Page 4: Brand Your Community Using Less and Gulp

•  Community Templates

•  Configure Visualforce Template to Community

•  Loading Visualforce Header/Footer to OOTB pages

•  Configure color code fields in “Community Configuration” custom object and add them to a apex controller

•  Less

•  Gulp

•  Generating CSS Visualforce component using Gulp

•  Demo: adding header to Customer and Partner communities

Agenda

Page 5: Brand Your Community Using Less and Gulp

Community Templates

Page 6: Brand Your Community Using Less and Gulp

Community Builder Based (KOKUA, KOA, NAPILI, and ALOHA)

•  Branding Editor to change colors and fonts

•  Site.com Studio to adjust templates

•  KOKUA, KOA for Knowledge and Cases

•  NAPILI for Knowledge, Cases, and Q&A

•  ALOHA App Launcher for Identity and Connected App

SALESFORCE TABS + VISUALFORCE

•  OOTB tabs

•  Use Visualforce Template + Header/ Footer components

Community Templates

Page 7: Brand Your Community Using Less and Gulp

Community Templates

Page 8: Brand Your Community Using Less and Gulp

Configure Visualforce Template

Page 9: Brand Your Community Using Less and Gulp

•  Select Salesforce Tabs + Viauslforce template type

•  Create Visualforce template and add header and footer Visualforce components to the teamplate

Create Visualforce Template

Page 10: Brand Your Community Using Less and Gulp

•  Configure the Visualforce template to community

Configure Visualforce Template in Community Site Details

Page 11: Brand Your Community Using Less and Gulp

OOTB Header / Footer

Page 12: Brand Your Community Using Less and Gulp

Salesforce Tabs + Visualforce template: OOTB pages

Page 13: Brand Your Community Using Less and Gulp

Configure Header / Footer html pages to the Salesforce Tabs + Visualforce template

•  Create Header / Footer html pages

•  Upload them to a Document folder

•  Configure them in Community Administration: Branding tab

Page 14: Brand Your Community Using Less and Gulp
Page 15: Brand Your Community Using Less and Gulp

•  Create Header / Footer Visualforce pages

•  Create jQuery script pages

•  Load jQuery script pages in HTML Header / Footer pages

Steps to load Visualforce Header / Footer for OOTB pages

Page 16: Brand Your Community Using Less and Gulp

•  Create Header / Footer Visualforce pages

•  Add Header / Footer Visualforce components to the pages

Header Example: SC_HTMLHeader.page

<apex:page applyHtmlTag="false" applyBodyTag="false" showHeader="false" sidebar="false” standardStylesheets="false”>

<c:SC_Header />

</apex:page>

Create Header / Footer Visualforce Pages

Page 17: Brand Your Community Using Less and Gulp

Header Example: SC_LoadHeader.page

<apex:page showHeader="false" sidebar="false" standardStylesheets="false" contentType="text/javascript" >

$j = $.noConflict();

$j(".header-wrap" ).load( "{!$Page.SC_HTMLHeader} #header" ,function(){

$j("div[role='banner']").remove();

$j(".zen-bodyZen").css("border-top", "0px");

});

</apex:page>

Using jQuery to load the Visalforce Header / Footer pages

Page 18: Brand Your Community Using Less and Gulp

Header Example: SC_CustomerHeader.html

<div class="header-wrap"></div>

<!-- Load jQuery -->

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

<!-- Load Visualforce page as a script -->

<script type="text/javascript" src="/customer/SC_LoadHtmlHeader"></script>

Header.html / Footer.html

Page 19: Brand Your Community Using Less and Gulp
Page 20: Brand Your Community Using Less and Gulp

Community Configuration Object

Page 21: Brand Your Community Using Less and Gulp

•  Create “Community Configuration“ custom object

•  Add fields for Brand Primary Color, Brand Secondary Color…etc

Configure color code fields in “Community Configuration” object

Page 22: Brand Your Community Using Less and Gulp

•  Query Community Configuration Record and assign values to properties

Apex controller

Page 23: Brand Your Community Using Less and Gulp

•  Create an empty Visualforce component named “SC_CSSMain.component”

CSS Component

Page 24: Brand Your Community Using Less and Gulp

Less

Page 25: Brand Your Community Using Less and Gulp

Front-end development framework, one of the most popular css pre-processors.

Mixins

.v-align {

display: inline-block;

vertical-align: middle;

}

#navbar{

.v-align;

}

Less

Page 26: Brand Your Community Using Less and Gulp

Nested Rule

#header-top{

.vertical-align;

.brand-color;

width: 100%;

height: 84px;

.header-left {

position: relative;

.vertical-align;

}

}

Less cont.

Page 27: Brand Your Community Using Less and Gulp

Variables

@brand-primary: #2084ba;

@brand-primary-dark: #165C82;

@brand-title-text-color: #F6F6F6;

#header-top{

.v-align;

background: radial-gradient(@brand-primary-color,@brand-primary-dark-color);

width: 100%;

height: 84px;

color: @brand-title-text-color;

}

Less cont.

Page 28: Brand Your Community Using Less and Gulp

•  IMap Visualforce merge fields to Less variables using ~

Map Visualforce merge fields to Less variables

Page 29: Brand Your Community Using Less and Gulp

Gulp

Page 30: Brand Your Community Using Less and Gulp

•  One of most popular JavaScript build tools (Grunt, Brunch…etc)

•  Gulpfile.js, defines build tasks. Great thing about “Gulpfile.js” is JavaScript code not configuration file.

•  Simple: 5 basic functions

•  gulp.task: registers function

•  gulp.run: run tasks

•  gulp.watch: watch file changes and run tasks

•  gulp.src: returns a readable stream

•  gulp.dest: return a writable stream

Gulp

Page 31: Brand Your Community Using Less and Gulp

“compileCSS” task to dynamically generate Visualforce SC_CSSMain.component and upload to SFDC org

Page 32: Brand Your Community Using Less and Gulp

Demo

Page 33: Brand Your Community Using Less and Gulp

Goal - Changing branding colors from SFDC internal tab without modifying code

•  2 Communities (Customer and Partner) using one code base

•  In Community Configuration custom object tab “Brand Customer Community” and “Brand Partner Community” records

•  Develop SC_Header.component

•  Style SC_Header.component in header.less

•  Configure VF merge fields in variable.less

•  Using Less and Gulp generating SCMainCSS.component

•  Change branding colors from SFDC internal tab without modifying code.

Demo: Add Header to Customer and Partner Community Using Less and Gulp

Page 34: Brand Your Community Using Less and Gulp

•  Gulp compiled less files

•  Because of the less variables, merge fields were generated to css files

background: radial-gradient({!BrandPrimaryColor}, {!BrandPrimaryDarkColor});

•  Gulp constructed SC_MainCSS.component

•  Gulp executed MavensMate command to saved SC_MainCSS.component to SFDC org.

•  SC_MainCSSCotroller read the brand colors in Community Configuration records based on the community name.

Here is what happened? Instead of uploading css to static resource…

Page 35: Brand Your Community Using Less and Gulp

“compileCSS” task to dynamically generate Visualforce SC_CSSMain.component and upload to SFDC org

Page 36: Brand Your Community Using Less and Gulp

Summary

Page 37: Brand Your Community Using Less and Gulp

•  Communtiy Templates: SALESFORCE TABS + VISUALFORCE

•  Visualforce Template

•  JQuery loading Visualforce Header/Footer Components to OOTB pages

•  “Community Configuration” custom object

•  Using Gulp + Less to generate SC_CSSMain.component

Summary

Page 38: Brand Your Community Using Less and Gulp

•  Multiple Communities with same code base

•  Managed Package

These techniques are useful when

Page 39: Brand Your Community Using Less and Gulp

•  Twitter: @shujiui

•  Github: https://github.com/shujiui

•  Slideshare: TBD

Call to Action

Page 40: Brand Your Community Using Less and Gulp

Q&A

Page 41: Brand Your Community Using Less and Gulp

Thank you