Managing common functionality on a site

I’m still getting used to Wappler - I like what I see, but before I grow the application too far I’d like to understand what is the best way to manage common components used on a page? In a standard app, I’d just move everything into a number of includes, but that doesn’t seem to be so obvious with Wappler…

For example, I have a navbar which I’ve moved into an include - it works, but I need some Server Connect modules to make it really usable to (for example) update the menu depending on the logged in state of the user. It doesn’t seem possible to add this to the include, so it seems I can really only use the navbar with dynamic features if it’s not in an include, but then I need to manage it on dozens of pages.

Is there a recommended way to manage this?

2 Likes

Hello,
You can use any dynamic data or expression in the includes, just the same way as on your page.

If I include a navbar in an include, then it is not editable using Wappler - I can edit the html directly, but I can’t edit it visually, or add any of the Wappler special sauce.

If I add the markup at the top of the include to make it an app, then I can edit it in Wappler, however this doesn’t actually work since I then get runtime errors since these includes are already loaded and can’t be loaded again. The specific error that pops up is something like “App is already running”.

Maybe there’s another way to do this, or I’m missing the point somewhere so I’d welcome further information on how to achieve this.

Thanks.

You can open your include in Wappler and edit it directly.
Are you sure you create your include in Wappler as per docs, and not just copy-pasting code in an empty php file?

1 Like

Thanks - I’d not seen the docs. I did create it using the -> button from my initial page, but may have subsequently broken it.

I will take a read through this and confirm if I’ve still got issues, but hopefully all will be explained there.

Thanks.

Unfortunately this doesn’t seem to work as I’d hoped. If I edit using the button in the SSI component, then I can visually edit the NavBar, however it seems that it doesn’t allow me to add any Server Connect components, and it also seems that there are no dynamic attributes that can be set.

For example, if I add a Header element directly to the main file, then I have a bunch of dynamic features I can set…

However if I add it to the include file, I don’t have these options…

Can you please post a screenshot of the code view of the include file?

You can’t use a PHP include on an HTML page. Your both pages must be saved as .php

When moving the content to a PHP include, also make sure to select ‘php include’ in the include type menu.

I was using php on both, but then decided to start with a fresh example. I've now renamed these all the php, and it doesn't seem to make a lot of difference.

I assume that the head-page tag in the header file is not important since I want this to be referenced from a lot of pages.

What else am I missing here?

Was the app connect framework included on the parent/main page before creating the serverside include?
It should not show ‘body’ in the structure but ‘app’ if app connect is added on the main/parent page.

Remember that the App Connect framework is required for almost all the components and functionality in Wappler.

1 Like

Thanks. That's what I was missing (I've only been using Wappler for a week, so still working through all this :wink: ).

By changing the comment on the start of the include file I have retro fitted this to my original project and it's working.

Thanks for the help.

1 Like

@Teodor one issue I’ve come across here is that when I add components into my included file, they are added with relative URLs. This works fine if the page is in the same folder as the include, but not when it’s in another folder.

Eg - I have a /navbar.php include file. This is included into /index.php so everything works fine. However, when I use the same include in /other/index.php, it doesn’t work since any components are included as relative links -:

<!-- Wappler include head-page="index.php" appConnect="local" is="dmx-app" bootstrap4="cdn" fontawesome_4="cdn" jquery_slim_33="cdn" -->
<dmx-serverconnect id="roles" url="dmxConnect/api/user/roles.php"></dmx-serverconnect>

I can of course edit this to make it an absolute reference and that works fine in all pages, but it seems that this should be handled better by Wappler?

Yes you should keep the included on the same level to avoid bad relative links.

Or set the links option in your project settings to site root relative so links are generated not as document relative but as site root relative.

This is also useful if you are using routing.

I think that's what I have, but they are still relative links -: