Logotype Sitevision Developer
Log in
Log in

appResource

The AppResource utility is used to access resources within a WebApp. Add the resources to the resource folder located in the root of the project.

js
import appResource from '@sitevision/api/server/appResource';

Methods

Resources can be accessed in three different ways, where pathToResource is the path to the file in the resource folder.

appResource.getContent(pathToResource)

Returns the resource as a UTF-8 based string.

appResource.getNode(pathToResource)

Returns the resource as a JCR Node (sv:image or sv:file).

Example

js
import * as React from 'react'; import { renderToString } from 'react-dom/server'; import App from './components/App'; import router from '@sitevision/api/common/router'; import properties from '@sitevision/api/server/Properties'; import appResource from '@sitevision/api/server/appResource'; router.get('/', (req, res) => { const fileContentAsString = appResource.getContent('message.txt'); const imageNode = appResource.getNode('images/vacation.png'); const uri = properties.get(imageNode, 'URI'); res.agnosticRender( renderToString(<App message={fileContentAsString} image={uri} />), { message: fileContentAsString, image: uri, } ); });
Resource folder example
Did you find the content on this page useful?