I came across something really simple but equally useful recently.
It is quite well known that Office 365 allows you to set a custom image as a logo for your organisation. This logo then appears in the suite bar across the entire tenant.
When working on an Office 365 Development project, we have multiple tenants to take care of. Typically, they are DEV, TEST, UAT and finally PROD.
When you are navigating between these tenants, a really simple way of telling them apart is to use a custom logo for each tenant!
We as developers might just quickly have a look at the URL to see which tenant we are in. But in many cases, the same tenants are used by non-technical members of the team who might need a clearer indication of which tenant they are in. This can also help in preventing someone accidentally doing something on the wrong tenant.
So here at Content and Code, we might have something like this:
Development Tenant:
Test Tenant:
UAT Tenant:
PROD does not require any special logo as that might confuse end users:
Here is how you set the custom theme and logo for your tenant:
This version adds the ability to add/retrieve Managers and Contributors to a Term Group in the SharePoint Online Term Store.
Here is a quick code snippet I put together for achieving this:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You can even define custom names/properties in your .spcolor files which can be used in your custom CSS. My colleague Matt Holden has a great post on this here:
Now, the SharePoint theming engine uses CSS comments to determine the color replacement:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
As per Matt's post, the theming engine replaces the values at run-time to the color defined in the ContentAccess1 section in the spcolor file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For the theming engine to successfully carry out this replacement, the ReplaceColor comment needs to be present in the CSS file we load in SharePoint.
When I minified the Themable.css file using the clean-css gulp plugin, it stripped out all the comments which made the replacement not work:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Adding an exclamation mark before the comment was not going to work as that would be invalid syntax for the SharePoint theming engine.
So my final solution was to convert the ReplaceColor comment to a special comment before processing it through the minifier, then letting the minifier do it's thing by minifying the css file but preserving the special comments, and then after the minification, again converting the special comment to a regular comment suitable for the SharePoint theming engine:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Which then gave me the minified CSS along with the required comments preserved:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I recently started playing around with Gulp and was not really impressed until I came across the gulp-spsave plugin. This plugin will let you upload your JS/CSS files directly to SharePoint right from Visual Studio 2015! This meant that I no longer had to manually upload my JS files to SharePoint or use SharePoint Designer to edit my JS/CSS files!
This got me more interested in Gulp and I started exploring how can I further improve my debugging and build workflow with Gulp. After spending some more time, I came up with a basic workflow which will definitely get you interested in Gulp as a SharePoint/Office 365 Developer!
This is a simple workflow which will look for predefined JavaScript files in your Visual Studio 2015 project. If any of your files change, it will be bundled into a single JavaScript file, minified and uploaded to SharePoint.
Here is the file structure of my Visual Studio 2015 project. It is a simple ASP.NET project where I have removed all unnecessary files. Since this is a strictly front-end/UI project, you could also open a folder in Visual Studio as described in this StackOverflow post.
The Scripts folder contains the JS files I will be working on. For demo purposes, I have copied the files from the Core.JavaScriptCustomization project in PnP.
The Output folder is where my output files GulpDemo.js and GulpDemo.min.js will be created. These will also be uploaded to SharePoint.
The GulpFile.js is where all my Gulp tasks will be defined.
The package.json file is where all the NPM packages required for my tasks will be defined.
So without further ado, here is the code for my Gulp tasks:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var rename = require('gulp-rename'); //renaming to min
var spsave = require('gulp-spsave'); //upload to SharePoint
//Bundle JS files together into a single file
gulp.task('concat-js', function () {
return gulp.src("./Scripts/**/*.js")
.pipe(concat("GulpDemo.js"))
.pipe(gulp.dest("./Output"))
});
//Minify the GulpDemo.js file. This task has a dependency on concat-js which means concat-js will always run before minify-js
gulp.task('minify-js', ['concat-js'], function () {
return gulp.src("./Output/GulpDemo.js")
.pipe(uglify())
.pipe(rename({ suffix: '.min'}))
.pipe(gulp.dest("./Output"))
});
//Upload GulpDemo.js and GulpDemo.min.js files to SharePoint. This task has a dependency on minify-js which means minify-js will always run before upload-to-sp
gulp.task('upload-to-sp', ['minify-js'], function () {