Building a blog into Anvil

I am moving an existing web project into Anvil. The current site is based in Wordpress and then uses Anvil to run Python scripts. Our client wants to move it all into Anvil and drop WP, including the blog.

Is this possible?

At a basic level they need to make new articles and them to get listed on an index page in cards (featuring an image). The blog articles could just be children under Form with a script that loops through them on that parent page. I have looked and I can’t find an example or tutorial to follow.

ps. I am php and JS developer more than Python

1 Like

Yep. All perfectly possible!

2 Likes

Welcome to the forum! You might want to look at the Data Grid tutorial: Anvil | Data Grids: Displaying Data In Tables That’s the component you’d use to display a list of blog posts. Clicking on one could take you to the detail page for that post.

2 Likes

You can take a look at

You can even clone the app if you want.

2 Likes

I have similar apps and I use the routing module of Anvil Extras. It works great, but it is not SEO friendly.

Have s look at this for a SEO friendly version of it: Serve anything, anywhere on your domain, with @anvil.server.route()

2 Likes

That looks perfect!

Can you give me access to the app to clone it or share a clone link for a template?

1 Like

I wondered if that would work as a starting point, but how much can you change the UI on Data Grids? Can they look like cards?

There are a lot of tools in Anvil. Data Grids use Repeating Panels under the hood, and provide some structure around how the data appears in the Repeating Panel. You might look at using Repeating Panels directly, you can completely customize the look of the items, at the cost of not having the paging built in.

… and you can even replace the repeating panel with a linear panel, and have the list dynamically load. See the AutoScroll custom component for an example.

1 Like

Typically, it doesn’t. Instead, the two share a database of articles.

Just add the existing table for the main app into the editor app.

I am nearly there.

I have copied the database table so it is shared from the editor into the blog (and I can see if I add an article it appears in the list in both). I have made sure it is called app_tables.articles but if I run the app no articles appear. If I rename it to app_tables.articles2 is errors (as expected) and if I change the permissions to none it also errors (as expected), so I know it is there and accessible.

What am I missing? I am not a Python dev, are the tools I can add to assist with debugging.

FYI. In the browser this returns empty: https://anvil.works/ide/background-tasks/Z2K2R5EXAB4FBJUB/

Can you be more specific about the issue? Does it happen in the main app or the editor app.

Also, I am not able to access the link you have shared (only you can access it).

To get detailed help, you either need to provide code in the forum, or provide a clone link.

It all looks good in the editor, but nothing gets pulled through to the public-facing app.

This is my public-facing app clone:

This is the editor clone:

Any thoughts would be appreciated

Sorry for not mentioning that. The articles are filtered by category. When you go to the FrontArticlesPage form, you will see a variable called self.categories containing the name and desc of the article

        self.categories=[
        {
            "name":"Articles",
            "desc":"Access all announcements, content and tutorials"
        },
        {
            "name":"Guidelines",
            "desc":"See our policies and guidelines"
        },                        
        ] 
        

Right now, it is looking for articles in the category of “Articles” and “Guidelines”. When creating an article in the category, you need to set the category for it to either of these categories.

You can change the name of these categories as per your needs but make sure that the articles also have the same name

That was the missing element to get the data displaying. Thank you!

What I have done is changed the category to a select field rather than a text field so the input matches what is expected in the code.

One (final) question. I have incorporate the blog logic into the rest of the project I am working on but I am unable to target the link from the card to update a parent container. Could someone take a look… and hopefully this will be the last time I ask for assistence.

Thank you for everyone’s help.

Here is a fixed clone link. You appeared to have commented out some critical lines

However I must warn you that the navigation on your app has become somewhat of a mess right now since the rest of your app is not using the hash routing but only the blog part is.

I haven’t properly documented the template (nor made it customizable enough to be working inside another app) so it might not be easy to get everything work well for you. Let me know if you need help with anything regarding that.