CMS Development

marvelouspatric
メンバー

real estate listing hubdb sample

Hi,

 

I'm trying to do the real estate listing for using Hubdb.  It's displaying the listing, but I can get it to filter or search.  I've copied and pasted the code from the tutorial and entered my table id.  Help?

 

<!-- set the filter by drop down, search bar, and submit button -->

<div>
<form id="form_id" method="get">

<div>
<h4>FILTER BY LISTING TYPE: </h4>
<select name="type" form="form_id" onChange="this.form.submit()">
<option value="show-all">Show All</option>
{% set types = hubdb_table_column(658170, "type").options %}
{% for choice in types %}
{% set type_list = type_list~choice.id|list%}
{% if choice.id == request.query_dict.type%}
<option selected="selected" value="{{ choice.id }}">{{ choice.name }}</option>
{% else %}
<option value="{{ choice.id }}">{{ choice.name }}</option>
{% endif %}
{% endfor %}
</select>
</div>
<div>
<input name="listing_address" type="text" id="search-by" class="autocomplete" placeholder="Search by City or Zip Code...">
</div>
<input id="submit-button" type="submit" value="search">

</form>
</div>

{% set queryparam = "" %}
{% if request.query_dict.type in ["1", "2", "3", "4"] and request.query_dict.listing_address == "" %}
{% set queryparam = queryparam ~ "&type="~request.query_dict.type|urlencode %}
{% endif %}
{% if request.query_dict.type in ["1", "2", "3", "4"] and request.query_dict.listing_address != "" %}
{% set queryparam = queryparam~"&type="~request.query_dict.type|urlencode~"&listing_address__icontains="~request.query_dict.listing_address|urlencode %}
{% endif %}
{% if request.query_dict.type == "show-all" and request.query_dict.listing_address != "" %}
{% set queryparam = queryparam~"&listing_address__icontains="~request.query_dict.listing_address|urlencode %}
{% endif %}

 

{% set table = hubdb_table_rows(658170, queryparam) %}

{% if table == [] %}
<p class='align-center'>Sorry, no listings found for that Search. Try changing your fiter and search again.</p>
{% else %}
{% for row in table %}
<div>
<div class="{{ row["type"].name }}">
<div><img src="{{ row["listing_image"].url}}"></div>
<div>
<h2>{{ row["listing_price"] }}</h2>
<h3>{{ row["listing_address"] }}</h3>
<h4>{{ row["type"].name }}</h4>
<div>
<ul>
<li><span>{{ row["listing_bedrooms"] }}</span><br>bd</li>
<li><span>{{ row["listing_baths"] }}</span><br>ba</li>
<li><span>{{ row["listing_sq_ft"] }}</span><br>sq ft</li>
<li><span>{{ row["listing_acres"] }}</span><br>acres</li>
</ul>
</div>
<div class="button"><a href="{{ row["listing_url"] }}">Details</a></div>
</div>
</div>
</div>
{% endfor %}
{% endif %}

3件の返信
FredSan
参加者

real estate listing hubdb sample

After 4 attempts and plenty of documentation review, I just realized that the search won't work until I posted my code into an actual published page.  The search feature now works (but only on the new published page).

 

Here's my working code: 

 

<!-- Set the filter by drop down, search bar, and submit button -->
<div>
<form id="form_id" method="get">
<div>
<h4>Filter by Listing Type: </h4>
<select name="type" form="form_id" onChange="this.form.submit()">
<option value="show-all">Show All</option>
{% set types = hubdb_table_column(2698095, "type").options %}
{% for choice in types %}
{% set type_list = type_list~choice.id|list %}
{% if choice.id == request.query_dict.type %}
<option selected="selected" value="{{ choice.id }}">{{ choice.name }}</option>
{% else %}
<option value="{{ choice.id }}">{{ choice.name }}</option>
{% endif %}
{% endfor %}
</select>
</div>

<!-- Search field -->
<div>
<input name="listing_address" type="text" id="search-by" class="autocomplete" placeholder="Search by City or Zip Code...">
</div>
<input id="submit-button" type="submit" value="search">

</form>
</div>

<!-- Set the different query parameters using submitted input for hubdb query -->
{% set queryparam = "" %}
{% if request.query_dict.type in ["1", "2", "3", "4"] and request.query_dict.listing_address == "" %}
{% set queryparam = queryparam ~ "&type="~request.query_dict.type|urlencode %}
{% endif %}
{% if request.query_dict.type in ["1", "2", "3", "4"] and request.query_dict.listing_address != "" %}
{% set queryparam = queryparam~"&type="~request.query_dict.type|urlencode~"&listing_address__icontains="~request.query_dict.listing_address|urlencode %}
{% endif %}
{% if request.query_dict.type == "show-all" and request.query_dict.listing_address != "" %}
{% set queryparam = queryparam~"&listing_address__icontains="~request.query_dict.listing_address|urlencode %}
{% endif %}

<!-- Render Listing database -->
{% set table = hubdb_table_rows(2698095, queryparam) %}

{% if table == [] %}
<p class='align-center'>Sorry, no listings found for that Search. Try changing your filter and search again.</p>
{% else %}
{% for row in table %}
<div>
<div class="{{ row["type"].name }}">
<div><img src="{{ row["listing_image"].url }}"></div>
<div>
<h2>{{ row["listing_price"] }}</h2>
<h3>{{ row["listing_address"] }}</h3>
<h4>{{ row["type"].name }}</h4>
<div>
<ul>
<li><span>{{ row["listing_bedrooms"] }}</span><br>bd</li>
<li><span>{{ row["listing_baths"] }}</span><br>ba</li>
<li><span>{{ row["listing_sq_ft"] }}</span><br>sq ft</li>
<li><span>{{ row["listing_acres"] }}</span><br>acres</li>
</ul>
</div>
<div class="button"><a href="{{ row["listing_url"] }}">Details</a></div>
</div>
</div>
</div>
{% endfor %}
{% endif %}

EricSalvi
HubSpot Employee
HubSpot Employee

real estate listing hubdb sample

Hey @marvelouspatric
I had a similar problem when I gave this a try a while ago. I relized I wasn't adding

{% set queryparam = "" %}
And all the other stuff inbetween.
{% endif %} 

in the correct place.


What happens if you move this section I have referenced above (Note: this is not theexact code) and move it so it starts right after <form id="form_id" method="get">

0 いいね!
htudor73
メンバー | Solutions Partner
メンバー | Solutions Partner

real estate listing hubdb sample

Does anyone know of a provider that I could call that can provide the real estate MLS API to HubDB integration?

0 いいね!