{% macro Folder(folder) %}
{% if hasAttr(folder,'children') %}
{% for f in getAttr(folder,'children') %}
{{Folder(f)}}
{% endfor %}
{% if hasAttr(folder,'security') %}
{{Security(getAttr(folder,'security'))}}
{% endif %}
{% else %}
{% endif %}
{% endmacro %}
{% macro Security(security) %}
{% for key,val in getAttr(security,'roles','roleAssignment','roleAssignments') %}
{% endfor %}
{% endmacro %}
{% macro SiteSecurity(security) %}
{% for admin in getAttr(security,'admins','additionalAdmins','administrators','additionalAdministrators') %}
{% endfor %}
{% for admin in getAttr(security,'owners','additionalOwners') %}
{% endfor %}
{% for admin in getAttr(security,'members','additionalMembers') %}
{% endfor %}
{% for admin in getAttr(security,'visitors','additionalVisitors') %}
{% endfor %}
{% if hasAttr(security,'siteGroups','groups') and hasItems(security,'siteGroups','groups') %}
{% for group in getAttr(security,'siteGroups','groups') %}
{% if hasAttr(group,'members') %}
{% for member in getAttr(group,'members') %}
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}
{% endmacro %}
{% macro CustomAction(action) %}
{% include getAttr(action,'commandUIExtensionFile') %}
{% else %}
/>
{% endif %}
{% endmacro %}
{% macro Feature(feature) %}
{% endmacro %}
{% macro TermGroup(group) %}
{% if hasAttr(group,'termsets','termSets') %}
{% for t in getAttr(group,'termsets','termSets') %}
{{TermSet(t)}}
{% endfor %}
{% endif %}
{% if hasAttr(group,'contributors') %}
{% for c in getAttr(group,'contributors') %}
{% endfor %}
{% endif %}
{% if hasAttr(group,'managers') %}
{% for m in getAttr(group,'managers') %}
{% endfor %}
{% endif %}
{% endmacro %}
{% macro Term(t) %}
{% if hasAttr(t,'terms') %}
{% for tt in getAttr(t,'terms') %}
{{Term(tt)}}
{% endfor %}
{% endif %}
{% if hasAttr(t,'customProperties') and hasKeys(t,'customProperties') %}
{% for key,val in getAttr(t,'customProperties') %}
{% endfor %}
{% endif %}
{% if hasAttr(t,'localCustomProperties') and hasKeys(t,'customProperties') or hasAttr(t,'linkUrl','url','targetUrl','linkTitle') %}
{% for key,val in getAttr(t,'localCustomProperties') %}
{% endfor %}
{% if hasAttr(t,'linkUrl','targetUrl','url') %}
{% endif %}
{% if hasAttr(t,'linkTitle','linkLabel') %}
{% endif %}
{% endif %}
{% endmacro %}
{% macro TermSet(tset) %}
{% if hasAttr(tset,'terms') %}
{% for t in getAttr(tset,'terms') %}
{{Term(t)}}
{% endfor %}
{% endif %}
{% if hasAttr(tset,'customProperties') and hasKeys(t,'customProperties') or hasAttr(tset,'navigation','nav') %}
{% for key,val in getAttr(tset,'customProperties') %}
{% endfor %}
{% if hasAttr(tset,'nav','navigation','isNavigation') %}
{% endif %}
{% endif %}
{% if hasAttr(tset,'localCustomProperties') or hasAttr(tset,'linkUrl','targetUrl','url','linkTitle','linkLabel') %}
{% for key,val in getAttr(tset,'localCustomProperties') %}
{% endfor %}
{% if hasAttr(tset,'linkUrl','targetUrl','url') %}
{% endif %}
{% if hasAttr(tset,'linkTitle','linkLabel') %}
{% endif %}
{% endif %}
{% if hasAttr(tset,'labels') %}
{% for key,val in getAttr(tset,'labels') %}
{% endfor %}
{% endif %}
{% endmacro %}
{% macro WebSettings(webSettings) %}
{% endmacro %}
{% macro AuditSettings(auditSettings) %}
{% for audit in getAttr(auditSettings,'audits') %}
{% endfor %}
{% endmacro %}
{% macro RegionalSettings(regionalSettings) %}
{% endmacro %}
{% macro ContentType(contentType) %}
{% set validation = validateContentType(contentType) %}
{{writeContentType(getAttr(contentType,'name','internalName','staticName'),getContentTypeId(contentType))}}
{% if hasAttr(contentType,'fieldRefs') and hasItems(contentType,'fieldRefs') %}
{% for field in getAttr(contentType,'fieldRefs') %}
{% endfor %}
{% endif %}
{% if hasAttr(contentType,'fields') and hasItems(contentType,'fields') %}
{% for fieldName in getAttr(contentType,'fields') %}
{% endfor %}
{% endif %}
{% if hasAttr(contentType,'documentSetTemplate') %}
{% if hasAttr(template,'allowedContentTypes') %}
{% for act in getAttr(template,'allowedContentTypes') %}
{% set contentTypeId = getContentTypeId(act) %}
{% if contentTypeId %}
{% else %}
{% endif %}
{% endfor %}
{% endif %}
{% if hasAttr(template,'defaultDocuments') %}
{% for doc in getAttr(template,'defaultDocuments') %}
{% endfor %}
{% endif %}
{% if hasAttr(template,'sharedFields') %}
{% for field in getAttr(template,'sharedFields') %}
{% endfor %}
{% endif %}
{% if hasAttr(template,'welcomePageFields') %}
{% for field in getAttr(template,'welcomePageFields') %}
{% endfor %}
{% endif %}
{% endif %}
{% endmacro %}
{% macro ComposedLook(composedLook) %}
{% endmacro %}
{% macro Field(field) %}
{% set taxFieldId = '' %}
{% if isTaxonomyField(field) %}
{% set taxFieldId = generateTaxonomyFieldId(getAttr(field,'id')) %}
{% endif %}
{% if hasAttr(field,'default') %}
{{getAttr(field,'default')}}
{% endif %}
{% if getAttr(field,'type') == "Choice" and hasAttr(field,'choices') %}
{% for item in getAttr(field,'choices') %}
{{item}}
{% endfor %}
{% endif %}
{% if getAttr(field,'type') == "ChoiceMulti" and hasAttr(field,'choices') %}
{% for item in getAttr(field,'choices') %}
{{item}}
{% endfor %}
{% endif %}
{% if getAttr(field,'type') == "MultiChoice" and hasAttr(field,'choices') %}
{% for item in getAttr(field,'choices') %}
{{item}}
{% endfor %}
{% endif %}
{% if getAttr(field,'type') == "Choice" and hasAttr(field,'mappings') %}
{% for item in getAttr(field,'mappings') %}
{{item.choice}}
{% endfor %}
{% endif %}
{% if getAttr(field,'type') == "Calculated" and hasAttr(field,'formula') %}
{{getAttr(field,'formula')|safe}}
{% endif %}
{% if getAttr(field,'type') == "Calculated" and hasAttr(field,'defaultFormula') %}
{{getAttr(field,'defaultFormula')|safe}}
{% endif %}
{% if getAttr(field,'type') == "Calculated" and hasAttr(field,'fieldRefs') %}
{% for ref in getAttr(field,'fieldRefs') %}
{% endfor %}
{% endif %}
{% if isTaxonomyField(field) %}
SspId
{{getAttr(field,'sspid')|default('{sitecollectiontermstoreid}')}}
TermSetId
{termsetid:{{getAttr(field,'termGroupName','groupName','termGroupId')}}:{{getAttr(field,'termSetId','termSet','termSetName')}}}
TextField
{{taxFieldId}}
IsPathRendered
{{getAttr(field,'isPathRendered')|default(false)}}
IsKeyword
{{getAttr(field,'isKeyword')|default(false)}}
{% endif %}
{% endmacro %}
{% macro List(list) %}
{% if hasAttr(list,'views') and hasItems(list,'views') %}
{% for view in getAttr(list,'views') %}
{{View(view)}}
{% endfor %}
{% elif getAttr(list,'createDefaultView') %}
{{log('Feature not supported','Creating default view is not supported yet')}}
{% endif %}
{% if hasAttr(list,'contentTypes') or hasAttr(list,'contentTypeIds') %}
{% if hasContentBindings(list) %}
{% for contentType in getAttr(list,'contentTypeIds') %}
{% endfor %}
{% for contentType in getAttr(list,'contentTypes') %}
{% if contentType != 'Item' %}
{% endif %}
{% endfor %}
{% endif %}
{% endif %}
{% if hasAttr(list,'dataRows') %}
{% for row in getAttr(list,'dataRows') %}
{% if hasAttr(row,'data') %}
{% for key,val in getAttr(row,'data') %}
{{val}}
{% endfor %}
{% endif %}
{% if hasAttr(row,'security') %}
{{Security(getAttr(row,'security'))}}
{% endif %}
{% endfor %}
{% endif %}
{% if hasAttr(list,'fieldDefaults') %}
{% for key,val in getAttr(list,'fieldDefaults') %}
{{val}}
{% endfor %}
{% endif %}
{% if hasAttr(list,'fieldDefs') %}
{% for field in getAttr(list,'fieldDefs') %}
{{Field(field)}}
{% endfor %}
{% endif %}
{% if hasAttr(list,'security') %}
{{Security(getAttr(list,'security'))}}
{% endif %}
{% if hasAttr(list,'folders') %}
{% for ff in getAttr(list,'folders') %}
{{Folder(ff)}}
{% endfor %}
{% endif %}
{% if hasAttr(list,'userCustomActions','userActions') %}
{% for action in getAttr(list,'userCustomActions' ,'userActions' ) %}
{{CustomAction(action)}}
{% endfor %}
{% endif %}
{% endmacro %}
{% macro NavigationNode(node) %}
{% if hasAttr(node,'children','items','nodes') %}
{% for n in getAttr(node,'children','items','nodes') %}
{{NavigationNode(n)}}
{% endfor %}
{% else %}
{% endif %}
{% endmacro %}
{% macro StructuralNavigation(structural) %}
{% for item in getAttr(structural,'nodes','children','items') %}
{{NavigationNode(item)}}
{% endfor %}
{% endmacro %}
{% macro View(list,view) %}
{% if hasAttr(view,'query') %}
{{getAttr(view,query)}}
{% endif %}
{% if hasAttr(view,'viewFields') and hasItems(view,'viewFields') %}
{% for viewField in getAttr(view,'viewFields') %}
{% endfor %}
{% endif %}
{{getAttr(view,'rowLimit')}}
{% if hasAttr(view,'aggregations') and hasItems(view,'aggregations') %}
{% for aggregation in getAttr(view,'aggregations') %}
{% endfor %}
{% else %}
{% endif %}
{% if hasAttr(view,'jsLink') %}
{{getAttr(view,'jsLink')|join('|')}}
{% else %}
clienttemplates.js
{% endif %}
{% if hasAttr(view,'xslLink') %}
{{getAttr(view,'xslLink')}}
{% else %}
main.xsl
{% endif %}
{% if hasAttr(view,'toolbar') %}
{% else %}
{% endif %}
{% endmacro %}
{% macro Navigation(navigation) %}
{% if hasAttr(navigation,'global','globalNav','globalNavigation') %}
{% set globalNav = getAttr(navigation,'global','globalNav','globalNavigation') %}
{% if getAttr(globalNav,'navType','type','navigationType') == "Managed" %}
{% endif %}
{% if hasAttr(globalNav,'structural') %}
{{StructuralNavigation(getAttr(globalNav,'structural'))}}
{% endif %}
{% endif %}
{% if hasAttr(navigation,'current','currentNavigation','currentNav') %}
{% set currentNav = getAttr(navigation,'current','currentNavigation','currentNav') %}
{% if getAttr(globalNav,'navType','type','navigationType') == "Managed" %}
{% endif %}
{% if hasAttr(currentNav,'structural') %}
{{StructuralNavigation(getAttr(currentNav,'structural'))}}
{% endif %}
{% endif %}
{% endmacro %}
{% macro File(file) %}
{% if hasAttr(file,'props','properties') %}
{% if getAttr(file,'isMasterPage') %}
{% endif %}
{% for key,val in getAttr(file,'props','properties') %}
{% if key == 'PublishingAssociatedContentType' %}
{% else %}
{% endif %}
{% endfor %}
{% endif %}
{% endmacro %}
{% macro Directory(directory) %}
{% endmacro %}
{% macro Page(page) %}
{% endmacro %}
{% macro AddContentTypeToPagesLibrary(contentType,def = false) %}
Write-Log "Adding {{contentType}} To Pages Library"
Add-PnPContentTypeToList -List "Pages" -ContentType "{{contentType}}" {% if def %} -DefaultContentType {% endif %}
{% endmacro %}
{% macro AddContentTypeToList(list,contentType) %}
Write-Log "Adding {{contentType}} To {{list}} List"
Add-PnPContentTypeToList -List "{{list}}" -ContentType "{{contentType}}"
{% endmacro %}
{% macro RemoveList(title,force) %}
Write-Log "Removing List {{title}}"
Remove-PnPList -Identity "{{title}}" {% if force %}-Force{% endif%}
{% endmacro %}
{% macro AddList(title,url,template) %}
Write-Log "Adding List {{title}}"
New-PnPList -Title "{{title}}" -Url "{{url}}" -Template "{{template}}"
{% endmacro %}
{% macro AddContentTypeToList(contentType,list) %}
Write-Log "Adding Content Type {{contentType}} to List {{list}}"
Add-PnPContentTypeToList -List "{{list}}" -ContentType "{{contentType}}"
{% endmacro %}
{% macro RemoveContentTypeFromList(title,list) %}
Write-Log "Removing Content Type {{title}} from List {{list}}"
Remove-PnPContentTypeFromList -List "{{list}}" -ContentType "{{title}}"
{% endmacro %}
{% macro RemoveContentType(contentType) %}
Write-Log "Removing Content Type {{contentType}} from web"
Remove-PnPContentType -Identity "{{contentType}}"
{% endmacro %}
{% macro SetListDefaultContentType(list,contentType) %}
Write-Log "Setting List {{list}} default content type to {{contentType}}"
Set-PnPDefaultContentTypeToList -List "{{list}}" -ContentType "{{contentType}}"
{% endmacro %}
{% macro AddFieldToContentType(field,contentType) %}
Write-Log "Adding field {{field}} to content type {{contentType}}"
Add-PnPFieldToContentType -Field "{{field}}" -ContentType "{{contentType}}"
{% endmacro %}
{% macro RemoveFieldFromContentType(field,contentType) %}
Write-Log "Removing field {{field}} from content type {{contentType}}"
Remove-PnPFieldFromContentType -Field "{{field}}" -ContentType "{{contentType}}"
{% endmacro %}
{% macro EnableFeature(id,force) %}
Write-Log "Enabling feature {{id}}"
Enable-PnPFeature -Identity {{id}} {% if force %} -Force {% endif %}
{% endmacro %}
{% macro DisableFeature(id,force) %}
Write-Log "Disabling feature {{id}}"
Disable-PnPFeature -Identity {{id}} {% if force %} -Force {% endif %}
{% endmacro %}
{% macro AddField(command) %}
Write-Log "Adding field {{getAttr(command,'displayName','name','internalName','id','staticName')}}"
Add-PnPField -DisplayName "{{getAttr(command,'displayName','title')}}" -InternalName "{{getAttr(command,'name','internalName','staticName')}}" -Type {{getFieldType(getAttr(command,'type'))}} {% if hasAttr(command,'list') %} -List {{getAttr(command,'list')}}{% endif %} {% if hasAttr(command,'id') %}-Id {{getAttr(command,'id')}}{% endif %} {% if hasAttr(command,'addToDefaultView','defaultView') %}-AddToDefaultView {% endif %} {% if hasAttr(command,'group') %}-Group "{{getAttr(command,'group')}}"{% endif %} {% if hasAttr(command,'requied') %}-Required{% endif %} {% if hasAttr(command,'clientSideComponentId') %}-ClientSideComponentId {{getAttr(command,'clientSideComponentId')}} {% endif %} {% if hasAttr(command,'clientSideComponentProperties') %}-ClientSideComponentProperties {{getAttr(command,'clientSideComponentProperties')}}{% endif %} {% if hasAttr(command,'choices')%}-Choices {{getAttr(command,'choices').join(',')}}{% endif %}
{% endmacro %}
{% macro RemoveField(field,list) %}
Write-Log "Removing field {{field}}"
Remove-PnPField -Identity "{{field}}" {% if list %}-List "{{list}}"{%endif%}
{% endmacro %}
{% macro AddPublishingPage(name,layout,title,publish,folder,meta) %}
Write-Log "Adding Publishing Page"
Add-PnPPublishingPage -PageName "{{name}}" -PageTemplateName "{{layout|default('BlankWebPartPage')}}" -Title "{{title}}" {%if publish %}-Publish{% endif %} {% if folder %}-Folder "{{folder}}" {%endif%}
{% endmacro %}
{% macro SetPublishingPageFields(meta,siteUrl,name) %}
{% if meta %}
Set-PnPFileCheckedOut -Url "{{siteUrl}}/Pages/{{name}}.aspx"
$item = Get-PnPFile -Url "{{siteUrl}}/Pages/{{name}}.aspx" -AsListItem
Set-PnPListItem -List "Pages" -Identity $item -Values @{ {% for key,value in meta %} "{{key}}"="{{value}}"; {%endfor%} }
Set-PnPFileCheckedIn -Url "{{siteUrl}}/Pages/{{name}}.aspx"
{% endif %}
{% endmacro %}
{% macro SetDefaultPageLayout(title) %}
Write-Log "Setting the default page layout to {{title}}"
Set-PnPDefaultPageLayout -Title "{{title}}"
{% endmacro %}
{% macro SetAvailablePageLayouts(allowPageLayouts,layouts,inheritPageLayouts) %}
Write-Log "Allowing page layouts {{layouts}}"
{% if allowPageLayouts %}
Set-PnPAvailablePageLayouts -AllowAllPageLayouts
{% elif layouts %}
Set-PnPAvailablePageLayouts -PageLayouts {{layouts}}
{% elif inheritPageLayouts %}
Set-PnPAvailablePageLayouts -InheritPageLayouts
{% endif %}
{% endmacro %}
{% macro AddMasterPage(title,path,desc) %}
Write-Log "Adding master page {{title}}"
Add-PnPMasterPage -SourceFilePath "{{path}}" -Title "{{title}}" -Description "{{desc}}"
{% endmacro %}
{% macro SetMasterPage(url,customUrl) %}
Write-Log "Setting default master page {{title}}"
Set-PnPMasterPage -MasterPageServerRelativeUrl {{url}}
{% endmacro %}
{% macro ClearRecycleBin(id,all,secondStageOnly,force) %}
Write-Log "Clearing recycle bin"
Clear-PnpRecycleBinItem {% if id %}-Identiy {{id}} {% endif %} {% if all %}-All {% endif %} {% if hasAttr(command,'secondStageOnly','secondStage') %} -SecondStageOnly {% endif %} {% if hasAttr(command,'force') %} -Force {% endif %}
{% endmacro %}
{% macro EnableAppSideLoading(enable) %}
Write-Log "Enabling app side loading"
Set-PnPAppSideLoading {% if enable %}-On {%else %} -Off {% endif %}
{% endmacro %}
{% macro SetHomePage(fileName) %}
Write-Log "Setting home page"
Set-PnPHomePage -RootFolderRelativeUrl Pages/{{fileName}}
{% endmacro %}
{% macro SendEmail(to,subject,body) %}
Write-Log "Sending Email to: {{to}}"
Send-PnPMail -To {{to}} -Subject {{subject}} -Body {{body}}
{% endmacro %}
{% macro Command(command) %}
{% set type = getAttr(command,'command','commandType') %}
{% if type == 'RemoveList' %}
{{RemoveList(getAttr(command,'name','id','title'),hasAttr(command,'force'))}}
{% elif type == 'AddList' %}
{{AddList(getAttr(list,'name','title'),getAttr(list,'url'),getAttr(list,'template'))}}
{% elif type == 'AddContentTypeToList' %}
{{AddContentTypeToList(getAttr(command,'name','title','internalName','staticName'),getAttr(command,'list'))}}
{% elif type == 'RemoveContentTypeFromList' %}
{{RemoveContentTypeFromList(getAttr(command,'name','title','internalName','staticName'),getAttr(command,'list'))}}
{% elif type == 'RemoveContentType' %}
{{RemoveContentType(getAttr(command,'name','title','internalName','staticName','id'))}}
{% elif type == 'SetListDefaultContentType' or type == 'ListDefaultContentType' %}
{{SetListDefaultContentType(getAttr(command,'list'),getAttr(command,'contentType'))}}
{% elif type == 'AddFieldToContentType' %}
{{AddFieldToContentType(getAttr(command,'field'),getAttr(command,'contentType'))}}
{% elif type == 'RemoveFieldFromContentType' %}
{{RemoveFieldFromContentType(getAttr(command,'field'),getAttr('contentType'))}}
{% elif type == 'EnableFeature' %}
{{EnableFeature(getAttr(command,'id','guid'),getAttr(command,'force'))}}
{% elif type == 'DisableFeature' %}
{{DisableFeature(getAttr(command,'id','guid'),getAttr(command,'force'))}}
{% elif type == 'AddField' %}
{{AddField(command)}}
{% elif type == 'RemoveField' %}
{{RemoveField(getAttr(command,'displayName','name','internalName','id','staticName'),getAttr(command,'list'))}}
{% elif type == 'SetMasterPage' %}
{{SetMasterPage(getConfig('spHost')+getConfig('url')+getAttr(command,'fileName'))}}
{% elif type == 'SetHomePage' %}
{{SetHomePage(getAttr(command,'fileName'))}}
{% elif type == 'AddMasterPage' %}
{{AddMasterPage(getAttr(command,'title','name'),getAttr(command,'path','filePath'),getAttr(command,'desc','description'))}}
{% elif type == 'DefaultPageLayout' or type == 'SetDefaultPageLayout' %}
{{SetDefaultPageLayout(getAttr(command,'title','name'))}}
{% elif type == 'SetAvailablePageLayouts' or type == 'AvailablePageLayouts' %}
{{SetAvailablePageLayouts(getAttr(command,'allowAllPageLayouts','allowAll'),getAttr(command,'layouts','pageLayouts'),hasAttr(command,'inheritPageLayouts'))}}
{% elif type == 'AddPublishingPage' %}
{{AddPublishingPage(getAttr(command,'name'),getAttr(command,'layout','pageLayout'),getAttr(command,'title'),getAttr(command,'publish'),getAttr(command,'folder'),getAttr(command,'meta'))}}
{% elif type == 'ClearRecycleBin' or type == 'EmptyRecycleBin' %}
{{ClearRecycleBin(getAttr(command,'id','identity'),getAttr(command,'all'),getAttr(command,'secondStageOnly'),getAttr(command,'force'))}}
{% elif type == 'AppSideLoading' or type == 'EnableAppSideLoading' or type == 'EnableSideLoading' %}
{{EnableAppSideLoading(getAttr(command,'enable'))}}
{% elif type == 'Email' or type == 'SendEmail' %}
{{SendEmail(getAttr(command,'to'),getAttr(command,'subject'),getAttr(command,'body'))}}
{% else %}
{{CustomCommand(command)}}
Write-Log "Unknown Command Type {{type}}"
{% endif %}
{% endmacro %}
{% macro CustomCommand(command) %}
{{getAttr(command,'fn')}} {% for param in getAttr(command,'params') %}{% if hasAttr(param,'name') %}-{{getAttr(param,'name')}} {% endif %} {% if getAttr(param,'isString') %}"{{getAttr(param,'value')}}"{%else%}{{getAttr(param,'value')}}{% endif %}{% endfor %}
{% endmacro %}
{% macro Commands(commands) %}
Write-Log "Executing commands..."
{% for command in commands %}
{{Command(command)}}
{% endfor %}
{% endmacro %}
{% macro Sequence(seq) %}
{% if hasAttr(seq,'SiteCollections') %}
{% for sc in getAttr(seq,'SiteCollections') %}
{% endfor %}
{% endif %}
{% if hasAttr(seq,'sites') %}
{% for site in getAttr(seq,'sites') %}
{% if hasAttr(site,'templates') %}
{% for temp in getAttr(site,'templates') %}
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}
{% endmacro %}
{% macro ProvisioningTemplate(template) %}
{% if hasAttr(template,'properties') and hasItems(template,'properties') %}{{log('Provisioning Template','Site properties')}}
{% for key,val in getAttr(template,'properties') %}
{% endfor %}
{% endif %}{{log('Provisioning Template','Site navigation')}}
{% if hasAttr(template,'navigation') %}
{{Navigation(getAttr(template,'navigation'))}}
{% endif %}
{% if hasAttr(template,'sitePolicy') %}{{log('Provisioning Template','Site policy')}}
{{getAttr(template,'sitePolicy')}}
{% endif %}
{% if hasAttr(template,'webSettings') %}{{log('Provisioning Template','Web settings')}}
{{WebSettings(getAttr(template,'webSettings'))}}
{% endif %}
{% if hasAttr(template,'regionalSettings') %}{{log('Provisioning Template','Regional settings')}}
{{RegionalSettings(getAttr(template,'regionalSettings'))}}
{% endif %}
{% if hasAttr(template,'auditSettings') %}
{{AuditSettings(getAttr(template,'auditSettings'))}}
{% endif %}
{% if hasAttr(template,'supportedUILanguages') %}{{log('Provisioning Template','Supported UI languages')}}
{% for lang in getAttr(template,'supportedUILanguages') %}
{% endfor %}
{% endif %}
{% if hasAttr(template,'features') %}{{log('Provisioning Template','Features')}}
{% set features = getAttr(template,'features') %}
{% if hasAttr(features,'site') %}{{log('Provisioning Template','Site features')}}
{% for feature in getAttr(features,'site') %}{{log('Provisioning Template','Site feature: '+getAttr(feature,'id'))}}
{% endfor %}
{% endif %}
{% if hasAttr(features,'web') %}{{log('Provisioning Template','Web features')}}
{% for feature in getAttr(features,'web') %}{{log('Provisioning Template','Site feature: '+getAttr(feature,'id'))}}
{% endfor %}
{% endif %}
{% endif %}
{% if hasAttr(template,'composedLook') %}
{{ComposedLook(getAttr(template,'composedLook'))}}
{% endif %}
{% if hasAttr(template,'security') %}{{log('Provisioning Template','Security')}}
{{SiteSecurity(getAttr(template,'security'))}}
{% endif %}
{% if hasAttr(template,'lists') and hasItems(template,'lists') %}{{log('Provisioning Template','Lists')}}
{% for list in getAttr(template,'lists') %}{{log('Provisioning Template','List',getAttr(list,'listTitle','title'))}}
{% if getAttr(list,'scope') != 'root' or getAttr(list,'scope') != 'sitecollection' %}
{{List(list)}}
{% endif %}
{% endfor %}
{% endif %}
{% if hasAttr(template,'contentTypes') and hasItems(template,'contentTypes') %}{{log('Provisioning Template','Content Types')}}
{% for ct in getAttr(template,'contentTypes') %}{{log('Provisioning Template','Content Type '+getAttr(ct,'name'))}}
{{ContentType(ct)}}
{% endfor %}
{% endif %}
{% if hasAttr(template,'fields','siteFields') and hasItems(template,'fields','siteFields') %}{{log('Provisioning Template','Site Columns')}}
{% for f in getAttr(template,'siteFields','fields') %}{{log('Provisioning Template','Site Column '+getAttr(f,'name')+' - '+getAttr(f,'id'))}}
{{Field(f)}}
{% endfor %}
{% endif %}
{% if hasAttr(template,'termGroups') %}{{log('Provisioning Template','Term Groups')}}
{% for group in getAttr(template,'termGroups') %}{{log('Provisioning Template','Term Group '+getAttr(group,'name'))}}
{{TermGroup(group)}}
{% endfor %}
{% endif %}
{% if hasAttr(template,'wikiPages') %}
{% for p in getAttr(template,'wikiPages') %}
{{Page(p)}}
{% endfor %}
{% endif %}
{% if hasAttr(template,'propertyBagEntries') and hasItems(template,'propertyBagEntries') %}
{% for value in getAttr(template,'propertyBagEntries') %}
{% endfor %}
{% endif %}
{% if hasAttr(template,'files') or hasAttr(template,'directories','folders','dirs') %}{{log('Provisioning Template','Files')}}
{% for pageLayout in getAttr(template,'pageLayoutDefinitions') %}
{{PageLayout(pageLayout)}}
{% endfor %}
{% for masterPage in getAttr(template,'masterPageDefinitions') %}
{{MasterPage(masterPage)}}
{% endfor %}
{% for file in getAttr(template,'files') %}{{log('Provisioning Template','File - '+getAttr(file,'src'))}}
{{File(file)}}
{% endfor %}
{% for folder in getAttr(template,'directories','folders','dirs') %}{{log('Provisioning Template','Folder - '+getAttr(folder,'src'))}}
{{Directory(folder)}}
{% endfor %}
{% endif %}
{% if hasAttr(template,'pagelayouts') or hasAttr(template,'pagelayouts') %}{{log('Provisioning Template','Page Layouts')}}
{% for layout in getAttr(template,'pagelayouts') %}
{{PageLayout(layout)}}
{% endfor %}
{% endif %}
{% endmacro %}
{% macro PageLayout(file) %}
{% for key,val in getAttr(file,'props','properties') %}
{% endfor %}
{% endmacro %}
{% macro MasterPage(file) %}
{% if hasAttr(file,'props','properties') %}
{% for key,val in getAttr(file,'props','properties') %}
{% endfor %}
{% endif %}
{% endmacro %}
{% macro ProvisionSubSite(s) %}
$parentWeb = {% if getAttr(s,'parentWeb') == '/' or getAttr(s,'parentWeb') == 'root' or not hasAttr(s,'parentWeb') %} $rootWeb {% else %} Get-WebByUrl -Url "$($rootWeb.ServerRelativeUrl)/{{getAttr(s,'parentWeb')}}" {% endif %}
$subWebUrl = "{{getAttr(s,'url')}}"
$fullSubWebUrl = "$($parentWeb.ServerRelativeUrl)/$($subWebUrl)";
$subweb = Get-WebByUrl -Url $fullSubWebUrl
if ($subweb -eq $null)
{
$subweb = New-PnPWeb -Title "{{getAttr(s,'title')}}" -Url "{{getAttr(s,'url')}}" -Template "{{getAttr(s,'template','baseSiteTemplate')}}" -Description "{{getAttr(s,'description')}}" -Web $parentWeb
}
Apply-PnPProvisioningTemplate -Path "{{getFilePath('site-'+getAttr(s,'id')+'-1.xml')}}" -Web $subweb
{% for ct in getAttr(s,'pagesLibraryContentTypes','pagesLibraryContentTypes') %}
Add-PnPContentTypeToList -List "Pages" -ContentType "{{ct}}" -Web $subweb
{% endfor %}
{% if getAttr(s,'defaultPagesContentType','pagesLibraryDefaultContentType','pagesContentType') %}
Set-PnPDefaultContentTypeToList -List "Pages" -ContentType "{{getAttr(s,'defaultPagesContentType','pagesLibraryDefaultContentType','pagesContentType')}}" -Web $subweb
{% endif %}
{% if hasAttr(s,'pagesFieldsSettings','pagesFieldSettings') %}
$dict = @{}
{% for fieldName,fieldSettings in getAttr(s,'pagesFieldsSettings','pagesFieldSettings') %}
{% for settingKey, settingValue in fieldSettings %}
{% if settingKey == 'indexed' or settingKey == 'Indexed' %}
$dict["Indexed"] = {% if settingValue %}$true{% else %}$false {% endif %}
{% elif settingKey == 'enforceUniqueValues' or settingKey == 'unique' or settingKey == 'EnforceUniqueValues' %}
$dict["EnforceUniqueValues"] = {% if settingValue %}$true{% else %}$false {% endif %}
{% elif settingKey == 'required' or settingKey == 'Required' %}
$dict["Required"] = {% if settingValue %}$true{% else %}$false {% endif %}
{% else %}
$dict["{{vkey}}"] = {{getPowershellValue(vvalue)}}
{% endif %}
{% endfor %}
Set-PnPField -Identity "{{fieldName}}" -List "Pages" -Values $dict -Web $subweb
{% endfor %}
{% endif %}
{% if s.homePage %}
Set-PnPHomePage -RootFolderRelativeUrl "{{getAttr(s,'homePage')}}" -Web $subweb
{% endif %}
{% for list in getAttr(s,'lists') %}
{% if hasAttr(list,'readSecurity') or hasAttr(list,'writeSecurity') %}
$list = Get-PnPList -Identity $listTitle -Includes ReadSecurity,WriteSecurity -Web $subweb
if ($list -ne $null){
{% if hasAttr(list,'readSecurity') %}
$list.ReadSecurity = {{getAttr(list,'readSecurity')}}
{% endif %}
{% if hasAttr(list,'writeSecurity') %}
$list.WriteSecurity = {{getAttr(list,'writeSecurity')|default(2)}}
{% endif %}
$list.Update()
$list.Context.ExecuteQuery()
}
{% endif %}
{% if hasAttr(list, 'fieldDefs', 'fieldDefinitions') %}
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
$list = Get-PnPList -Identity "{{getAttr(list,'title')}}" -Web $subweb
$listContentTypes = $list.ContentTypes
$list.Context.Load($listContentTypes);
$list.Context.ExecuteQuery()
foreach ($ct in $listContentTypes){
$links = $ct.FieldLinks
$list.Context.Load($links)
$list.Context.ExecuteQuery();
}
{% for def in getAttr(list, 'fieldDefs', 'fieldDefinitions') %}
{% if def.addToContentTypes %}
$field = Get-PnPField -List "{{getAttr(list,'title')}}" -Identity "{{def.name}}" -Web $subweb
{% for item in def.addToContentTypes %}
foreach ($ct in $listContentTypes){
$links = $ct.FieldLinks
if ($ct.Name -eq "{{item}}")
{
$found = $false
foreach($link in $links){
if ($link.Name -eq "{{def.name}}")
{
$found = $true
}
}
if ($found -ne $true)
{
$link = new-object Microsoft.SharePoint.Client.FieldLinkCreationInformation
$link.Field = $field
$ct.FieldLinks.Add($link)
$ct.Update($false)
$list.Context.ExecuteQuery()
}
}
}
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}
{% if hasAttr(list,'fieldsSettings','fieldSettings') %}
{% for fieldName,fieldSettings in getAttr(list,'fieldsSettings','fieldSettings') %}
$dict = @{}
{% for settingKey, settingValue in fieldSettings %}
{% if settingKey == 'indexed' or settingKey == 'Indexed' %}
$dict["Indexed"] = {% if settingValue %}$true{% else %}$false {% endif %}
{% elif settingKey == 'enforceUniqueValues' or settingKey == 'unique' or settingKey == 'EnforceUniqueValues' %}
$dict["EnforceUniqueValues"] = {% if settingValue %}$true{% else %}$false {% endif %}
{% elif settingKey == 'required' or settingKey == 'Required' %}
$dict["Required"] = {% if settingValue %}$true{% else %}$false {% endif %}
{% else %}
$dict["{{vkey}}"] = {{getPowershellValue(vvalue)}}
{% endif %}
{% endfor %}
Set-PnPField -Identity "{{fieldName}}" -List "{{getAttr(list,'title')}}" -Values $dict -Web $subweb
{% endfor %}
{% endif %}
{% endfor %}
{% endmacro %}