wvuweb / cleanslate-cms

A place to file issues and view releases for CleanSlate CMS. http://cleanslatecms.wvu.edu
6 stars 0 forks source link

Want to use `remove` with web_request function for FormAssembly Forms #277

Closed dmolsen closed 1 year ago

dmolsen commented 1 year ago

WVU Online has an embedded Request for Information form on their site (example) that's built using FormAssembly. FormAssembly is the form building tool for TargetX/Salesforce. By using FormAssembly, WVU Online can ensure that new leads are added directly to CRM when they submit the form.

The current process requires that any edits (e.g. program listing) made by the FormAssembly administrator be manually copied into the CleanSlate theme. I'd like to explore using the "REST API" version with the site. This means the theme requests the form on page load.

I can use the web_request filter(?) to include the form in the page (example page, component in theme) and example code:

{{ "https://wvu.tfaforms.net/rest/forms/view/218064" | web_request }}

In order to let WVU Online control the styles for the form, I need the <link> tags removed from the output. I tried using the remove filter (docs) but nothing seemed to change. I don't know if that's because of quotes or something else.

Is it possible to remove content from the web_request option?

nreckart commented 1 year ago

Nothing prevents you from using replace on the result of a web_request. All web_request does is return the body of the response, as text.

Not sure what specific replace calls you were using, but the replace filter is very basic. In order to use it in this case, you'd need to replace the exact <link> element text.

{% liquid
  assign html = "https://wvu.tfaforms.net/rest/forms/view/218064" | web_request

  assign link1 = '<link href="https://wvu.tfaforms.net/dist/form-builder/5.0.0/wforms-layout.css?v=c27d5c00969ab611503d20373ee7309db2d05f22" rel="stylesheet" type="text/css" />'
  assign link2 = '...'
  assign link3 = '...'

  assign html = html | replace: link1, '' | replace: link2, '' | replace: link3, ''
%}

That's a pretty brittle solution that would break anytime the href or anything else in the links change.

There's currently no regex replace options, which would probably help, but that still feels dirty.

The strip_html filter exists, but it strips ALL html. A filter that lets you strip selected elements would be helpful.

You could try doing something like assign html = html | replace '<link ', '<nolink ', which would just turn the <link> into some undefined element, but that feels super dirty and would probably blow up the world at some point.

Or...you could just wrap all this HTML processing in a Lambda and just use that as the web_request.

nreckart commented 1 year ago

Just realized my brain swapped replace for remove.

Not sure I was even aware of the remove filter, so there's a chance it's been added to the main liquid repo, but not available in CleanSlate, yet. I'll need to look into that more.

That being said, replace can be used to achieve the same result, as described in my previous comment.

dmolsen commented 1 year ago

The Lambda idea may not be bad. I agree that the original concept is brittle. The Lambda CSS strip function might have other uses than just this individual use case. I'm doing a similar web request thing in the home page. Kim/Rebecca may appreciate not having to fight against those styles. Let me look into it.

dmolsen commented 1 year ago

Doing this with Lambda. Example works with web_request.