3

We are building a Commercial Real Estate site for a fairly large commercial real estate company and we're coming from an older custom-built site and there is a work flow and associated data logic we're having trouble figuring out how to best replicate in Craft.

When they list properties for sale or lease, they have a set of common fields for a given building (ex. address, photos, city, etc) and then sometimes need to add Units within that building, each with its own set of fields (ex. size, unit number, price, etc).

Sometimes these Unit(s) get listed all together on the one listing (or in the Craft sense, entry) on the front end. However, sometimes they need to be listed separately on the front end (ie. individual Units can be chosen to show up as their own listing (or separate entry)). This is in varying combinations (ie. any Unit could be flagged to show as separate - but not all Units need to). In this case, those separate Units still share (and display) the common building fields (ex. address, photos, city, etc).

What this means from an entry point of view, is we potentially need multiple URL slugs to get to each listing when some Units are flagged to show separately (for example: sale/building1, sale/building1-unit200, sale/building1-unit303 ...or whatever).

So what we're trying to solve us how to handle this. We are trying to preserve an intuitive and easy workflow for the editor, where they go add a new listing on one entry page, and via a Matrix field could add multiple Units - and within each Matrix Unit block, could have a toggle field that says "Show this unit as a separate listing").

The question then is how to access those "show as separate" units on the front end as they technically all share the same URL slug?

We briefly considered using related fields (separating out units as entries and the common building data as entries) but that would become incredibly difficult to remember, maintain and organize for which units belonged to what buildings across many hundreds of listings and thousands of units. As well, many buildings do not even have units.

We also considered a custom plugin that would create a duplicate entry for each flagged Unit when the entry is saved (and conversely remove duplicated entries when a Unit is unflagged). That seems kludgy and possibly complicated but maybe we're wrong on that? Also, not certain if there'd be a way to hide those duplicate entries from users in the CP so they're not confused by those (as they're always thinking that they work on one single entry for each building with its units).

Any thoughts on how to tackle this would be greatly appreciated.

2
  • "The question then is how to access those "show as separate" units on the front end as they technically all share the same URL slug?" For that particulair issue you could just make a light switch or checkbox if you'd like and just show this type of unit only when the lightswitch or checkbox is active. What I do most of the time is play around alot with these. This way you can be really efficient with creating options for webpages or matrix blocks so you don't need alot of blocks / different types of entries Mar 17, 2017 at 15:51
  • Thanks Justin but I don't think that addresses the core issue. If a listing has 3 Units and 1 is set to 'show separate' then on the front end there are 2 versions of this entry to show - one for the 'separate unit' version and one for the listing with the 2 other units. They both exist as separate listings to the public end user - but originate from one entry.
    – Mike
    Mar 17, 2017 at 16:15

2 Answers 2

1

One option to consider would be to use a structure, with the 'building' as a parent entry and the 'units' as children entries (with corresponding entryType of 'building' or 'unit' to set a unique field layout if needed).

Based on whatever logic makes most sense you could then display the building, the building with some subset of data from the units (children), or just the unit. The logic could be either an explicit checkbox or switch on the building or unit entries, or just the mere presence of unit entries (children).

In the structure's settings you can also set whether the 'unit' (child) URI pattern is building/unit (i.e. {parent.uri}/{slug}) or building-unit (i.e. {slug} or {parent.uri}-{slug}).

This should keep everything organized in the CMS and give you a lot of flexibility in terms of what to display where. The building can access the unit data and the unit can access the building data as needed.

2
  • Thanks Douglas. This certainly could work in certain contexts. However, I could see having to manage that structure adding a lot of admin work for the user. I forgot to set out that our site is built around a listings search engine (maybe I'm too close to the space and thought that would be a given). Anyway, our answer below takes that into account and means the admin never has to worry about anything other then adding and editing listing entries.
    – Mike
    Mar 18, 2017 at 9:00
  • No worries. That makes perfect sense. Mar 20, 2017 at 17:16
1

After looking at this more, we realized the answer wasn't all that complex. We just needed a way to differentiate the context in order to write out the correct data from the single entry. In our case, we're having to build a map-based search engine for the site (think something similar to Zillow) and what we'll do there is simply check against each entry result and whether is has any Units flagged as "show separate" (the flag field will be one field in a Matrix block holding all relevant Unit data fields). If it does, we'll simply use the data from the single entry to return the appropriate number of results with the different Unit data.

Each of those results will then have a URL to go to a details view that includes a URL segment if the listing is a "separate unit" version. Something like: sale/entry-id-or-slug/matrix-block-id. (That Matrix block ID could also be another field in the corresponding Matrix block if we wanted to use the actual Unit number (ie. 203)).

Then the detail template will check for that last URL segment parameter and if it exists, it will use the corresponding Matrix data for that Unit and ignore the other Unit(s). And if it does not find that last URL segment, then it just returns a normal entry with all Units data not set to "show as separate listing".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.