Forum Discussion
Robin Güldenpfennig
Jun 26, 2017Brass Contributor
Where did the Placeholder class move to?
Just updated the Pernille-Eskebo/sp-webpart-base NPM package to 1.1.1 and now it seems that the Placeholder control is either obsolet or moved to another place. Can anyone help me out? The ch...
Jun 26, 2017
sp-application-base
Robin Güldenpfennig
Jun 26, 2017Brass Contributor
Thanks mate. But now I got the problem that the Placeholder is missing the render function so it can't be used as a JSX element any more.
Am I missing something?
Am I missing something?
- Jun 26, 2017
I would probably create a new project and pick up the latest version of the solution with :
yo @microsoft/sharepoint
It looks like you might have some old versions mixed up with new version of things.
- Robin GüldenpfennigJun 26, 2017Brass ContributorI created a new project with Yeoman. Still got the same problem. I'm not able to use the Placeholder any more. Could you try and confirm it please? It's really strange.
- Jun 26, 2017
I went through the examples this morning. and the code below works for me:
import { override } from '@microsoft/decorators'; import { Log } from '@microsoft/sp-core-library'; import { BaseApplicationCustomizer, Placeholder } from '@microsoft/sp-application-base'; import * as strings from 'helloWorldStrings'; import styles from './AppCustomizer.module.scss'; import { escape } from '@microsoft/sp-lodash-subset'; const LOG_SOURCE: string = 'HelloWorldApplicationCustomizer'; /** * If your command set uses the ClientSideComponentProperties JSON input, * it will be deserialized into the BaseExtension.properties object. * You can define an interface to describe it. */ //export interface IHelloWorldApplicationCustomizerProperties { // This is an example; replace with your own property // testMessage: string; //} export interface IHelloWorldApplicationCustomizerProperties { Header: string; Footer: string; } /** A Custom Action which can be run during execution of a Client Side Application */ export default class HelloWorldApplicationCustomizer extends BaseApplicationCustomizer<IHelloWorldApplicationCustomizerProperties> { // These have been added private _headerPlaceholder: Placeholder; private _footerPlaceholder: Placeholder; @override public onInit(): Promise<void> { Log.info(LOG_SOURCE, `Initialized ${strings.Title}`); return Promise.resolve<void>(); } @override public onRender(): void { console.log('CustomHeader.onRender()'); console.log('Available placeholders: ', this.context.placeholders.placeholderNames.join(', ')); // Handling the header placeholder if (!this._headerPlaceholder) { this._headerPlaceholder = this.context.placeholders.tryAttach( 'PageHeader', { onDispose: this._onDispose }); // The extension should not assume that the expected placeholder is available. if (!this._headerPlaceholder) { console.error('The expected placeholder (PageHeader) was not found.'); return; } if (this.properties) { let headerString: string = this.properties.Header; if (!headerString) { headerString = '(Header property was not defined.)'; } if (this._headerPlaceholder.domElement) { this._headerPlaceholder.domElement.innerHTML = ` <div class="${styles.app}"> <div class="ms-bgColor-themeDark ms-fontColor-white ${styles.header}"> <i class="ms-Icon ms-Icon--Info" aria-hidden="true"></i> ${escape(headerString)} </div> </div>`; } } } // Handling the footer placeholder if (!this._footerPlaceholder) { this._footerPlaceholder = this.context.placeholders.tryAttach( 'PageFooter', { onDispose: this._onDispose }); // The extension should not assume that the expected placeholder is available. if (!this._footerPlaceholder) { console.error('The expected placeholder (PageFooter) was not found.'); return; } if (this.properties) { let footerString: string = this.properties.Footer; if (!footerString) { footerString = '(Footer property was not defined.)'; } if (this._footerPlaceholder.domElement) { this._footerPlaceholder.domElement.innerHTML = ` <div class="${styles.app}"> <div class="ms-bgColor-themeDark ms-fontColor-white ${styles.footer}"> <i class="ms-Icon ms-Icon--Info" aria-hidden="true"></i> ${escape(footerString)} </div> </div>`; } } } } private _onDispose(): void { console.log('[CustomHeader._onDispose] Disposed custom header.'); } }