Creating New Content Based on the Example App

The Scrivito Example App often serves as a basis for implementing many and varied use cases. But what if all the content it comes with is simply too much? In this guide we are going to show you how to remove the default content and start from scratch with just a couple of pages. We’re also going to explain how to use the main navigation and how the included overview pages are structured.

For this tutorial, you don’t need to download or clone the Example App and execute it locally because we are not going to touch any files in the codebase. Just open your Example App in the browser. Let’s start!

Remove the default content

First, after opening your Example App in the browser, make sure to have “scrivito/” in the URL path as the first element after the hostname. Then create a working copy for applying all the changes we’re going to make. Set the display mode to “Edit” using the switch at the top of the page.

Next, open your browser’s JavaScript console and change the context from top to scrivito_application.

We will delete all content from the working copy, i.e. each and every CMS object, to start fresh and create our new pages. Run this script in the console and watch the content vanish. (This script along with many other usage examples can also be found in our SDK Cheat Sheet.)

Copy
Scrivito.load(() => {
  return [...Scrivito.Obj.all()];
}).then(objs => {
  objs.forEach(o => {
    console.log(`Deleting ${o.id()}...`);
    o.destroy();
  });
  console.log("Done deleting all objs.");
});

After executing this script, your CMS is empty (in the selected working copy), and you will get a 404 error because the page that was displayed before is gone. Don’t publish this working copy if the Scrivito CMS you are working with includes valuable or publicly visible content. You will lose this content if you do!

Create the homepage

In the Example App, the homepage object is equipped with several attributes from which the app code obtains various settings like page-specific styling options or site-specific access keys for third-party services like Google Analytics. So let’s create a homepage!

Note that we cannot use the “Create page” item from the page menu for this because the Homepage type has been excluded from the selection dialog to prevent editors from creating homepages in addition to the one provided. So we’ll use the browser console again and create an instance of the built-in Homepage object model class:

Copy
Scrivito.getClass("Homepage").create({ _path: "/" });

As you can see, we’ve given the homepage a path by setting its _path attribute to “/”. By default, the page with this path is the root page. The Example App uses it for storing the site settings, and it also represents the origin of the main navigation (we’ll expand on this in a moment).

After executing the above statement in the console, the homepage should be displayed; however, it may take a couple of seconds until its initial content, a section widget containing a headline widget with its preset text, becomes visible. Try adding widgets, rearranging them, etc., like you probably already did prior to erasing the default content.

Did you notice the grey box at the bottom of the page? This is the footer. It is represented by a widgetlist so that it’s editable just like regular page content. Only the homepage has a footer widgetlist, however, this widgetlist will be rendered for all pages in the CMS. This is why the footer content can be edited on every page.

To see all the other options the homepage has in store for you, open its page settings via the menu at the top right and, for example, change the logo or the header image by uploading an image file. The various tabs of the properties dialog let you access the site settings, the social cards, etc. Many and diverse customization options await your attention – see Changing the Look of the Example App for inspiration.

Now, click the red magnifying glass at the top right corner of the page, then search for “lorem”. The 404 error you’ll get is the reason why we need to provide a search results page.

Provide the search results page

Creating the search results page via the console is as easy as creating a page of any type. At this point, we recommend taking a look at the Example App’s page model classes and their React components, or getting to know the basic principles of Diversifying Website Content Using Object Classes later on. For now, just execute:

Copy
Scrivito.getClass("SearchResults").create({ title: "Search Results" });

Like the homepage, the search results page is not available in the page type selection dialog, and thus you cannot create one using Scrivito’s editing interface – for the same reason: The default content includes such a page, and having more than one search results page doesn’t make any sense.

Repeating the search should now yield one result (unless you’ve changed the headline of the homepage). As with all new pages you might be creating, the search results page should be fine tuned via its properties view.

Next, let’s add a page to the navigation.

Populate the navigation

Did you notice the blue handle next to the magnifier? It represents an automatically generated navigation, which is part of the layout and shows up on all pages except landing pages.

Adding a <code>Page</code>

Technically, this navigation renders links for the pages that are (path-wise) located underneath the homepage. There are no subpages to the homepage yet, so nothing can be seen here until you select “Add page” from this menu and choose a page type, e.g. Page. This will cause a navigation item, initially <UNTITLED>, to appear for the new page. The item will update as soon as the page title is set via the page properties – try it out!

Adding a <code>LandingPage</code>

Next, let’s create a landing page! Usually, landing pages don’t show up in any navigation (and also don’t have a navigation), meaning that they don’t need a path. This is exactly what you get when using “Create page” from the page menu to create a page: it won’t have a path.

Another common practice regarding landing pages is to exempt them from the site search because they should be accessible only by their individual URLs (used in Google ads, Facebook posts, and the like).

But, how can we, as Scrivito users, find a specific landing page? There’s two easy methods: First, directly after creating a landing page, open its properties and assign a permalink to it – you don’t want its URL path to be something like “join-the-javascript-revolution-bbadaad6a47887cd” anyway. You can then enter this permalink name after the hostname in the browser’s address field, like with “https://mysite.scrivito.net/javascript-revolution”.

Secondly, especially if you have many landing pages, open the Content Browser and use the search or the ”Pages” filter list to find a specific page and, again, copy/paste its permalink (or object ID from the “System” tab) to the browser’s address line.

Using overview pages and widgets

Overviews are great for visitors looking for content of a specific kind, e.g. guides, news, products, etc. The Scrivito Example App presents several ways to implement overviews:

  • The "SearchResults" page has its own logic for displaying the search results.
  • A blog comes to life by several components working together: a Blog page, a BlogOverviewWidget on it, and any number of Blogpost pages not part of the page hierarchy.
  • A JobOverviewWidget or EventOverviewWidget doesn’t require special page logic and can be placed on pages of any type.

What has been said above about the SearchResults page type, applies to the Blog type as well: Both have been excluded from the page type selection dialog to prevent the creation of further instances of them next to the one in the default content. – You don’t require two or three blogs, do you?

So if you want to use the Example App's blog, you can add it as a subpage of the homepage by executing this in the console:

Copy
Scrivito.getClass("Blog").create({ _path: "/blog", title: "Blog" });

It’s the “/blog” path that makes this page a subpage of “/”, the homepage. After creating the blog, add a HeadlineWidget and a BlogOverviewWidget to the page and start providing blog posts using “Create page” from the page menu. To make use of the tag filter of the Blog page, assign suitable tags to the posts.

That was it! If you want to, go ahead and add further pages to the navigation, or stand-alone pages (without a path)...

Summarized ...

After removing the default content of the Example App, you can use the page and widget types it provides to add your own content and choose how it’s made accessible to visitors: via the navigation (utilizing the page hierarchy), as stand-alone pages, or by linking them in a text widget, for example.

For getting the most out of the Example App, we recommend to install it locally and to adapt the existing page and widget types according to your demands, or to create custom page types or custom widget types to cover your individual use cases.