Skip to content

Commit

Permalink
more cleanup + workaround for tsup not detecting new folders
Browse files Browse the repository at this point in the history
  • Loading branch information
sigdestad committed Dec 20, 2023
1 parent c72b86c commit 9424077
Show file tree
Hide file tree
Showing 16 changed files with 125 additions and 196 deletions.
12 changes: 0 additions & 12 deletions code-samples/layouts/two-columns/two-columns.html

This file was deleted.

40 changes: 0 additions & 40 deletions code-samples/layouts/two-columns/two-columns.ts

This file was deleted.

20 changes: 0 additions & 20 deletions code-samples/layouts/two-columns/two-columns.xml

This file was deleted.

53 changes: 25 additions & 28 deletions docs/layouts.adoc
Original file line number Diff line number Diff line change
@@ -1,63 +1,61 @@
:imagesdir: media/
:sourcedir: ../
:sourcedir: ../src/main/resources
:experimental:

= Layouts
= Bonus: Layout components

Layouts are like parts, but also support regions

== Two column layout

In this chapter, you'll be making a layout with two columns. Each column declares a region to support more components. We'll also support configuration of the layout, so editors can control the sizes for each of those two columns.
Unlike parts, layouts may contain regions. Here, we'll define two regions, each working as columns in the final result. We'll also throw in some configuration options so editors can control the sizes for each of those two columns.

Like for parts and pages, layout consists of a descriptor, the controller and a view - which have already been setup:

. Let's start by **adding the descriptor** for the `two-columns` layout:
+
.src/main/resources/site/layouts/two-columns/two-columns.xml
[source,xml]
----
include::{sourcedir}code-samples/layouts/two-columns/two-columns.xml[]
include::{sourcedir}/layouts/two-columns/two-columns.xml[]
----
+

Notice that it doesn't change much from what you've seen so far. It's basically a mix of pages and parts.
+
. **Add the controller**:
+

.src/main/resources/site/layouts/two-columns/two-columns.ts
[source,ts]
----
include::{sourcedir}code-samples/layouts/two-columns/two-columns.ts[]
include::{sourcedir}/layouts/two-columns/two-columns.ts[]
----
+
. **the view**:
+

.src/main/resources/site/layouts/two-columns/two-columns.html
[source,html]
----
include::{sourcedir}code-samples/layouts/two-columns/two-columns.html[]
include::{sourcedir}/layouts/two-columns/two-columns.html[]
----
+
. and finally, the layout needs **some styling**:
+

== Page contribution

To spice up the tutorial, we include some css which will only be available on pages where this layout exists. The following file has been placed in the assets folder:

.src/main/resources/assets/styles/two-columns.scss
[source,scss]
----
include::{sourcedir}code-samples/layouts/two-columns/two-columns.scss[]
include::{sourcedir}/assets/styles/two-columns.scss[]
----

So far, the only new section is the https://developer.enonic.com/docs/xp/stable/framework/contributions[pageContributions] you see in the controller.
NOTE: The `scss` file is automatically converted to `css` by the build system

Its naming speaks for itself, but just for clarity, is's a way for components to inject HTML on certain places within the resulting markup. Those places are on the `head` tag begin or end, or on `body` tag begin or end - and typically controlled by the page component.
To inject the css dynamically, we use a trick called https://developer.enonic.com/docs/xp/stable/framework/contributions[pageContributions].

In our case we used it to inject a reference to the `two-columns.css` asset when this layout is placed on a page.
Its naming speaks for itself, but just for clarity, it's a way for components to inject HTML on certain places within the resulting markup. Those places are on the `<head>` begin or end, or on `<body>` begin or end.

NOTE: `scss` is automatically converted to `css` during build
Study the TypeScript controller response above to see how the pageContribution is passed along with the response.

== Using the layout

So far you've understood what a layout is and, created the code for a two column layout. Let's see in practice by adding it to a page and using its regions.

. Go to the root site content and click on btn:[edit]
. *Setup the "Hello Regions!" page component*, and insert the two-column layout in its main region:
. Back in content studio btn:[edit] the site content (root item) once more.
. *Insert the two-column layout* in the main region:
+
image::two-column-layout.png["Two column layout with 50/50 config and no component in its left and right regions", width=1024px]
+
Expand All @@ -73,9 +71,8 @@ image::two-column-layout-33-66-with-texts.png["Two column layout with 33/66 conf
and https://developer.enonic.com/docs/xp/stable/cms/pages/layouts[layouts^].




== Summary

By combining content types, layouts, parts, pages and page templates, the sky's the limit for what you can build.

As already mentioned, regions accepts all kinds of parts, so by combining layouts with your custom parts, together with their own custom configurations, you can basically achieve any kind of design!
The journey so far has provided you a starting ground to build your first website. Let's now take a look on how to <<go-online#, go online>>!
12 changes: 6 additions & 6 deletions docs/menu.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@
"document": "parts"
},
{
"title": "6 - Layouts",
"document": "layouts"
},
{
"title": "7 - Page templates",
"title": "6 - Page templates",
"document": "page-templates"
},
{
"title": "8 - Static assets",
"title": "7 - Static assets",
"document": "static-assets"
},
{
"title": "8 - Bonus: Layouts",
"document": "layouts"
},
{
"title": "9 - Go online",
"document": "go-online"
Expand Down
45 changes: 21 additions & 24 deletions docs/pages.adoc
Original file line number Diff line number Diff line change
@@ -1,70 +1,67 @@
:experimental:
:imagesdir: media/
:sourcedir: ../
:sourcedir: ../src/main/resources/site/pages

= Visualize your content with pages

For every page, there is always a page component.

== Page component
At the moment, we have some content, but no preview or visual rendering.

Pages are composed from one or more components.
At the moment, we have some content, but no preview or visual rendering. Pages to the rescue. Page are composed from one or more components, always with a page component as its root.

Your app includes a pre-defined page component named `hello`. It is defined by a descriptor file, placed in a particular location within your app:
Your app includes a pre-defined page component named `hello`. It is defined by a descriptor file, placed in a particular location within your app: `src/main/resources/site/pages`

.src/main/resources/site/pages/hello/hello.xml
.pages/hello/hello.xml
[source,js]
----
include::{sourcedir}src/main/resources/site/pages/hello/hello.xml[]
include::{sourcedir}/hello/hello.xml[]
----

TIP: Like content types, you can define a form for the component using the https://developer.enonic.com/docs/xp/stable/cms/schemas[schema system].
TIP: Like content types, you can also define a form for the component using the https://developer.enonic.com/docs/xp/stable/cms/schemas[schema system^]. We'll get back to this later.

== Component controller

Enonic supports rendering with 3rd party front-ends, but is also capable of rendering by itself thanks to the https://developer.enonic.com/docs/xp/stable/framework[JS framework], which we will be using throughout this tutorial.
Enonic XP supports rendering with 3rd party front-ends, but is also capable of rendering by itself thanks to the https://developer.enonic.com/docs/xp/stable/framework[JS framework]. We will be using this throughout the rest of this tutorial.

When rendering with the Enonic framework, each component may have its very own controller, responsible for rendering it. Here is what it looks like in our case:
Each component may have its very own controller, responsible for its rendering. Here is what it looks like in our case:

NOTE: The controller file must use the same name as the component directory.
NOTE: The controller file must be placed in and use the same name as the component directory.

.src/main/resources/site/pages/hello/hello.ts
.pages/hello/hello.ts
[source,js]
----
include::{sourcedir}src/main/resources/site/pages/hello/hello.ts[]
include::{sourcedir}/hello/hello.ts[]
----

NOTE: Here we're using TypeScript. Each .ts file will automatically be compiled, and a .js file placed in the same folder. XP uses the resulting .js file.
NOTE: Here we're using TypeScript. Each .ts file will automatically be compiled by the build system, and the generated .js file placed in the same location. XP picks up and invokes the resulting .js file.

== Templating

For clean coding, we have also supplied a simple HTML template - a.k.a the View in the Model View Controller (MVC) pattern. It look like this:
For clean coding, we have also supplied a simple HTML template - a.k.a the View of the Model View Controller (MVC) pattern. It looks like this:

.src/main/resources/site/pages/hello/hello.html
.pages/hello/hello.html
[source,HTML]
----
include::{sourcedir}src/main/resources/site/pages/hello/hello.html[]
include::{sourcedir}/hello/hello.html[]
----

NOTE: This view is plain HTML, but also uses a specific syntax known as the https://market.enonic.com/vendors/enonic/thymeleaf-lib[Thymeleaf^] templating language. The Enonic runtime also supports many other options, such as https://market.enonic.com/vendors/enonic/react4xp-lib[React^], https://market.enonic.com/vendors/enonic/mustache-lib[Mustache^] and https://market.enonic.com/vendors/tineikt/freemarker-xp-library[Freemarker^]


== Create page
== Page one

For the `hello` page component render something, it must be associated with a content item:
For the `hello` page component to actually render something, it must be used by a content item:

. Select the Site content item - `Hello World` and click btn:[edit]
. *Select the Site content item* - `Hello World` and click btn:[edit]
. From the preview panel on the right, select the `Hello` page component in the list. Your changes will automatically save, and the page preview will render the result.

image::hello-world.gif["Demonstrating the process of setting up a page", width=1920px]

TIP: To learn more about pages, visit the https://developer.enonic.com/docs/xp/stable/cms/pages[pages] documentation.
image::hello-world.gif["Setting up the page", width=1920px]

== Summary

At this point we were able to attach a hello page component to the hello-world site content, which is great!
At this point we were able to attach a hello page component to the hello-world site content, which is great! A good observer will notice that the page is not entirely static, it will ouput the content `displayName` followed by a hardcoded text ` - we made it!`.

A good reader will note the page is not static, i.e, it will ouput a `displayName` followed by a hardcoded text ` - we made it!`... but that's it.
TIP: To learn more about pages, visit the https://developer.enonic.com/docs/xp/stable/cms/pages[pages documentation^].

Next you'll be introduced to the <<concept of regions>>, that will enable you to add more components to your pages.
Loading

0 comments on commit 9424077

Please sign in to comment.