osama7901 osama7901 - 1 month ago 18
PHP Question

how to make news and articles using the same silverstripe news module?

I need to incorporate News and Announcements in my silverstripe website, both news and announcements have the exact same structure and they both use https://github.com/nyeholt/silverstripe-news. in the html template I have two sections one for the news and another for the announcements.

what is the proper way to implement this:


  • should I just copy and past the /news module folder and use one for the news and the other for announcements.

  • or add another db field as flag to specify if this is a news article or an announcement article, but then in the cms the user would have to check this every time.

  • or is there anything else, I don't know


Answer

Duplicating the folder would not have the result you expect unless youd rename all the classes in side of the new one.

Basically the folder is just a place for the classes to be, not something that you access when you actually request an news article, you use SilverStripes routes for that.

Static assets would be something that are be loaded from a module folder.

The best way to add a new behaviour to an extension is to use a DataExtension.

See https://docs.silverstripe.org/en/3.4/developer_guides/extending/extensions/

Other way would be if the module uses sitetree for placing the "news holder". Then you have the option also to just create two holders with different names and then if you want to show a list of a paricular parent just filter with the parentId that relates to the correct holder.