DNN Liquid Content quick tips

In DNN Evoq, there’s a structured content solution called Liquid Content. The visualizers used to put that content on a DNN web page use the Liquid template language (I believe it uses dotliquid under the hood). Here’s a few things that’ve been useful to me:

If statement with a checkbox value

Sometimes my users want to be able to choose whether a link opens in a new tab. So I added a checkbox to the content type. Now, I expected it’d be as simple as {% if {{imgOpenInNewTab}} %}target="_blank"{% endif %}. Sadly it wasn’t.

After quite a lot of fiddling, I discovered I had to use the first filter, like so:

{% if {{imgOpenInNewTab.first}} == 'Yes' %}target="_blank"{% endif %}

Working with images

When you want to add an image to the template, add one to your content type and then add it to the template, like so: {{ image }}. It’ll output the entire image tag for you.

But what if you want to do something with the img element? Maybe set your own alt text, or specify other HTML attributes on there. This is where the image_url filter comes in. It returns the URL of the image. You’d use it like this:

<img src="{{ image | images_url }}" alt="" />

Working with absolutely massive images

Sometimes the people putting content into the system will upload a 3000px image from somewhere like Unsplash. DNN has the facility to scale images using the DNN Image Handler (and cache them on the server). You’d set the img src to something like /DnnImageHandler.ashx?mode=file&w=700&resizemode=fit&file=path-to-file. How do we use this with Liquid Content? It’s rather tricky, but it can be done, making use of lots of Liquid Template loops, variables and filters:

Firstly, the Image Handler doesn’t work with SVG images, so first we’ll need to figure out if the image is an SVG:

{%- assign file_extension = image | images_url | split: "." | last | split: "?" | first -%}

Then we need to get the server-local path to the image, (i.e. strip the https://example.com/ off the front). This is a bit complicated:

{%- assign local_image_url = image | images_url | remove_first: "http://" | remove_first: "https://" | split: "/" -%}

Then, pass it to the DNN image handler, stripping off the querystring as we go:

<img src="/DnnImageHandler.ashx?mode=file&w=700&resizemode=fit&file={%- for item in local_image_url -%}{%- unless forloop.first -%}/{%- if forloop.last -%}{%- assign not_qs = item | split: "?" -%}{{ not_qs.first }}{%- else -%}{{item}}{%- endif -%}{%- endunless -%}{%- endfor -%}" alt="" />

Finally, sometimes when an image has funny chracters in the filename it ends up as a .aspx URL, so we can’t do this at all. So all in, we end up with this:

{%- assign file_extension = image | images_url | split: "." | last | split: "?" | first -%}
{%- assign local_image_url = image | images_url | remove_first: "http://" | remove_first: "https://" | split: "/" -%}
{%- if file_extension == "svg" -%}
    <img src="{{ image | images_url }}" alt="" />
{% elsif file_extension == "aspx" %}
    <img src="{{ image | images_url }}" alt="" />
{%- else -%}
    <img src="/DnnImageHandler.ashx?mode=file&w=700&resizemode=fit&file={%- for item in local_image_url -%}{%- unless forloop.first -%}/{%- if forloop.last -%}{%- assign not_qs = item | split: "?" -%}{{ not_qs.first }}{%- else -%}{{item}}{%- endif -%}{%- endunless -%}{%- endfor -%}" alt="" />
{%- endif -%}

Now that might all seem a bit overkill, but if your content editors are prone to uploading 3000px images from Unsplash, this helps deal with the problem.

A DNN shout-out

I’ve started building websites using DNN recently. There’s been quite a learning curve, but there’s some amazing tools and resources which have made life a hell of a lot easier for me. So here’s a shout out:

  • nvQuickSite is a brilliant little tool which makes firing up new installations of DNN a breeze
  • nvQuickTheme (from the same people) is a great place to start when building a new DNN Theme or Skin
  • OpenContent (by Sacha Trauwaen) is a brilliant module for building structured content in DNN. If, like me, you’ve spent a lot of time working with SharePoint, you can think of OpenContent as Content Types, Lists and the Content Query Web Part, but a hell of a lot nicer. As much as I loved XSLT, I don’t miss it using it – I can choose between Handlebars and Razor here, depending on how complex things need to get. I’ve used it for all sorts of stuff – from news feeds to video galleries and “meet the team” modules.
  • Matt Rutledge’s Yo DNN Generator has come in really handy for building new DNN modules from scratch. Same is true of Chris Hammond’s Visual Studio Templates.
  • The DNNConnect group on Facebook is full of really helpful people who know DNN inside out.
  • Aderson Oliviera’s Youtube Channel and Open Friday initiative.

I’m sure there’s more I’ve forgotten. I feel pretty proficient with DNN now, but I couldn’t have got there without the help from all of the people and tools here. Thanks y’all.

Using the DNN Services Framework API with fetch

When building an SPA module in DNN (formerly Dotnetnuke), you’ll likely find yourself using the DNN WebAPI. It turns out the Javascript API for this is very XHR-centric. I wanted to use the fetch API instead.

When using fetch, instead of using beforeSend: setModuleHeaders() you’ll need to build the headers object yourself:

fetch(url, { headers: {
    "ModuleId": your-module-id-here,
    "TabId": your-tab-id-here,
}})

I modified this dotnetnuclear code to look more like this:

let service = {
    path: "PathToMyModule",
    framework: $.ServicesFramework(sbgQuestionnaireModule_Context.ModuleId),
    controller: "MyController"
}
service.baseUrl = service.framework.getServiceRoot(service.path);
// Set the headers
service.headers = {
    "ModuleId": service.framework.getModuleId(),
    "TabId": service.framework.getTabId()
};
// Set the anti-forgery token
if (service.framework.getAntiForgeryValue()) {
    service.headers["RequestVerificationToken"] = service.framework.getAntiForgeryValue();
}
service.loadUrl = service.baseUrl + "/" + service.controller + "/load";
fetch(service.loadUrl, {
    headers: service.headers
})
// etc

Thanks to Daniel Valadas for his help getting started with this.

Reflection

We pulled into Wolverhampton station and I looked across, thinking I was seeing a reflection of my train in the window of the Pumpkin cafe.

That is until the reflection started moving. My train was stood still. I was looking through a window at another train platform. Things are not always what they appear to be.

It took me straight back to the Roppingi Hills complex in Tokyo, where we saw an exhibition by Leandro Erlich: “Seeing and Believing”. He took us through a series of set pieces designed to test our assumptions.

My favourite piece was the mock hairdressers’ salon. The mirrors on one side of the room worked perfectly – showing my reflection. The mirrors on the other side were broken. No, broken is the wrong word they just didn’t work properly. They reflected the room but not the people in it, as if we were vampires. In fact there was a completely different group of people in those mirrors. It took me a little while to figure out what was going on.

I was looking through a window at another salon.

In Shadow

This is a rather wonderful piece of work.

(via jwz)

Lucy

On 28th January 2017, my mum, Lucy Mary Hodgson passed away after a long battle with Lymphoma. Here is the eulogy I read at her funeral.


Thank you for coming to celebrate Lucy’s life with us. It means a lot to see you all here. We can’t possibly hope to fully capture her in this eulogy everybody has their own perspective, but we’ll do our best. When I say we my Granny Mary and aunt Paula had a big hand in this.

Lucy was born in Stratford upon Avon on 20th April 1956. She was the eldest daughter and the third of seven children. Mary, her mother, described her as “an exceptionally beautiful baby who rarely cried”. Some qualities are clearly set at a very early age.

The family moved to Woking when Lucy was five and she attended the Providence Convent School, which was situated on the site of this church. She was a confident little girl and played the leading role of Little Red Riding Hood in a school production.

However, as she got older and changed schools she became shy, quiet and self-effacing. Perhaps because of this people often underestimated her. She was amongst the first intake when the new St John the Baptist School opened here in Woking.

She enjoyed spending a lot of time at the swimming pool with her sisters and by the age of twelve she could swim a mile. Throughout her life whenever she was near the sea she’d want to get in for a quick dip even in ridiculous Welsh winter conditions.

On leaving school she went to work at Slocock`s Nursery and studied horticulture concurrently at Merrist Wood.

Later, working in the greenhouses at Woking Park, she met and fell in love with the park’s foreman, Adam Hodgson. They married in 1979 and moved to Guildford where Adam started a landscaping business Adam the Gardener.

To help the business Lucy became adept at administration and book-keeping. They bought an early Amstrad PC, and she was soon an expert with spreadsheets and accounting software long before most people even knew what they were.

They had four children: me, Alice, Florence and Abigail. Lucy loved motherhood; her children were her pride and joy, she adored their company and would do anything for them.

Lucy had fond memories of her own childhood camping holidays, travelling all over the UK in a succession of family minibuses and converted ambulances. She kept up this tradition with her own family, making numerous trips to France, North Wales and even the Isle of Man to see the TT Races. Sometimes we joined forces with Sheila, Stephen or our friends’ families, camping en-masse so all the children and adults could play together.

She also took the family further afield to soak up the culture and sunshine in Malta, Cyprus, Florence, Rome and Florida.

Lucy travelled to Sri Lanka on her own, to Vietnam with her sister Sheila, and on a variety of European trips with her mother and as many of her siblings as possible. She loved to savour the local sights, cuisine and wine with her family.

She would have loved to have travelled more – she dreamed of seeing fall in Vermont, and of visiting her brother-in-law Piers in Australia. She loved to hear about all her children’s adventures too firing her own imagination.

Her husband Adam was a keen motorcyclist. He and Lucy attended many events together including all night rides and large weekend events with the local classic motorbike club.

In 1994 Adam died in a motorcycle accident, so Lucy was left to close the business and bring up her children alone. His sudden death when Abigail was only two was a crushing blow; but she faced this, as with all the challenges life threw at her, with dignity and fortitude. She was a very private person and kept most of her worries to herself.

Adam supported Crystal Palace football club. Lucy took up his season ticket and we cheered them on from the Holmesdale Terrace together for a couple of seasons. She supported them ever since taking great delight on the rare occasions when they embarrassed a much bigger team. I still remember her singing variations on “Que sera sera” when they were doing particularly well.

When we children had all started school or university, Lucy looked for work and for a while had three part-time jobs helping various small businesses with their admin.

Finally, she began working in the office of Woodbridge Hill Surgery, just around the corner from her home. She loved the job and adored the people she worked with. She started small, effectively just sorting the post. Over time she grew tremendously, taking on more and more complex roles. She worked her way right to the top, becoming Practice Manager an achievement she was rightfully very proud of.

Lucy had many hidden talents. In Woking at her old home there are several remarkable paintings completed when she was in her 20s. She carried on dabbling throughout our childhood, and in more recent years became a fixture at a local art class, developing her own signature watercolour style and making some good friends. Every year she would exhibit her work and sell her own Christmas cards and then downplay her accomplishments.

Not only was she a very talented artist, she could name most plants by their Latin names, and tell you when to prune them. She loved gardening, and every year she had some Gooseberries, Raspberries and Sweet Peas on the go. She could help you with your tax return. She knew all the details of football leagues and transfers, Formula 1 fixtures and tennis tournaments (all of which are quite incomprehensible to the rest of her siblings). She was a friend of the Royal Academy, a member of the National Trust and of the Guildford Cinema Club. She became engrossed in TV series as diverse as Star Trek, Doctor Who and Masterchef. More recently she took up badminton and proudly stuck to a workout regime at a local gym.

She loved music, attending festivals and gigs at first as a teenager, and then later with her own children. She saw some really big names over the years. Her vinyl record collection is huge and she would relish the opportunity to get them out and dance around the living room, usually with one or more of her daughters. Whenever we were planning to embark on a long car journey, she would compile a mix-tape to liven up the trip and make the miles fly by.

She was also a big reader, regularly losing herself in a good book. Her most recent accomplishment was completing the entire back catalogue of Kate Atkinson.

Although she lived in Guildford she came every Saturday night to Woking to attend mass here with Mary, and then to stay and catch up over supper and a glass of wine.

She was never particularly evangelical about her faith it was a very personal thing. She knew where she was going, and that gave her strength right at the end.

Lucy had a sweetness and kindness about her that made her the perfect restful company she was one of those people that made you feel better the moment they appeared. She was funny, sympathetic and constantly good natured.

Nevertheless, she had strong views about everything, from politics and current affairs to books, films, artists, as well as food and travel.

I loved chatting with her over a long drawn out breakfast (her poison was bacon) discussing anything and everything, especially if it was on the front page of the Guardian.

She was open-minded, with no big expectations of you. She wasn’t pushy, but rather wanted you to find your own way. She would love you whatever you did and she loved to hear all about it, too.

She got great pleasure from simple things; a new baby, cats, a Belgian chocolate truffle, a Stevie Wonder track, chickens, jigsaws, Sudoku, a good cheese, a glass of Petit Chablis in the sun, and all of our big family gatherings especially Christmas in Woking and new year in Cheltenham with Stephen and Helen.

Of course, the new baby Lucy was most excited about was Alice and Angus’s daughter. She was thrilled to be a grandmother and loved to spend time with little Astrid, see the latest photos and to hear about every stage in her development.

A little over a year ago Lucy was diagnosed with a rare and very aggressive blood cancer. One of the things I’m most proud of is how she faced up to it: Her attitude was always strong, positive and forward-looking. Although she was often scared, she found the strength to push on through and take on the next challenge. Even at her lowest, she never gave up hope.

In her mind, the future was always bright. And of course, it still is it’s just that now we’ll have to face it without her gentle loving presence.

Knee pads

We’re at Betws-y-coed, riding the Marin trail on a damp Monday afternoon. It’s the final leg of Alex’s stag weekend, which has involved the fantastic Penmachno trails, gorge walking, a crazy tree-top adventure, a parachute simulator and the odd pint of local ale, amongst other things.

We roll off the fire-road and into the final descent. Simon first, then Brett, me, Anton, Alex and Matt. Si sets off in his usual style: like an ICBM aimed at the far end of the trail. The rest of us roll in behind him, pedalling like maniacs to try and keep up.

We’re moving down the singletrack at ludicrous speed. It’s big, wet, rocky stuff. Properly rocky. North Wales rocky. It gets to the point where I have to back off a bit because my forks aren’t working very well I’m getting really quite scared.

We arrive at a particularly evil off-camber corner with a really rough run-in. Si has a big moment on the way through and stops a bit further up. Brett gets it wrong on the way in and has to really wrestle the bike around. I get all slidey going through the corner but manage to hold it together. Anton goes one better, losing the front wheel on the wet rocks and going down hard.

He bounces straight back up looking more or less unscathed, but for some reason he’s saying “That’s not good. That’s really not good.”

I look him up and down and can’t see what’s wrong. Then I look at his bike, which seems to be in one piece. I’m about to congratulate him on a spectacular crash when he lifts up the leg of his shorts to reveal the gash in his knee.

I can see his kneecap.

That’s really quite unpleasant.

Several stitches later, he’s off the bike for a few weeks while it heals up.

Earlier that day, when we were getting changed into our biking kit, he put his shoes on before realising he hadn’t put on his knee pads. “Ah bugger it” he said, and didn’t bother.

Magic people

I broke a gear cable on the Cannondale, so when last tuesday’s Hotsingletrack ride rolled around, Tim very kindly lent me his classic Voodoo.

We met up with the others on Leckhampton Hill in the pouring rain. Luckily that eased off a bit, but after a few weeks of foul weather the trails were coated in a thick layer of thick, wet mud. Here I was, on a completely unfamiliar bike, riding in some of the most challenging conditions I could imagine. In the dark. Game on.

Just like the last time I borrowed it, I finished up the ride wanting to keep the Voodoo. It’s a lovely bike, all light, pingy and playful. It’s an XC race bike at heart, though. You can’t just sit back and cruise. Faced with a climb? Hammer up it. Deep mud? Hammer through it. Stretch of road? Big ring it leaving everyone else for dead.

And the descents? YEAH BABY! Off the brakes, BRAARP! OK, so I spent more time travelling sideways than forwards and there was at least one spectacular leapfrog-the-bars dismount. It was proper fun though, drifting everywhere, mud flying in all directions, whooping as we went. Especially comical was the sight of the two Marks dragging their bikes across a field, wheels completely clogged up with the thick, claggy mud.

I still haven’t fixed the ‘dale, and Tim’s put a shorter stem and wider bars on the Voodoo now. I wonder…