{% extends "_layouts/main_solspace" %}


{% block content %}
	{% set slug = craft.app.request.segments|last %}
	{% set member = craft.imatrix.member('', 137) %}

	<h1>Welcome to the {{slug}} page</h1>

	<p>Craft thinks this is the template used: /{{craft.app.request.segments|join('/')}}. This is the template used to load this page.</p>

	<p>With slug <code>{{slug}}</code>, we can now fetch data based on this value.</p>

	<h2>Member data</h2>

	{% if member.has_errors is not defined %}

		<table>
			<thead>
				<tr>
					<th>Key</th>
					<th>Value</th>
					<th>Template code</th>
				</tr>
			</thead>

			<tbody>
				<tr>
					<td>Member ID</td>
					<td>{{member.member_id}}</td>
					<td><code>{{ '{{craft.imatrix.member(slug).member_id}}' }}</code></td>
				</tr>

				<tr>
					<td>Name</td>
					<td>{{member.name}}</td>
					<td><code>{{ '{{craft.imatrix.member(slug).name}}' }}</code></td>
				</tr>

				<tr>
					<td>Email</td>
					<td>{{member.email}}</td>
					<td><code>{{ '{{craft.imatrix.member(slug).email}}' }}</code></td>
				</tr>

				<tr>
					<td>Phone</td>
					<td>{{member.phone}}</td>
					<td><code>{{ '{{craft.imatrix.member(slug).phone}}' }}</code></td>
				</tr>

				{% if member.purchase_url is defined %}
				<tr>
					<td>Purchase Link</td>
					<td><a href="{{member.purchase_url}}">Link to "Go and purchase"</a></td>
					<td>Use <code>{{ '{{craft.imatrix.member(slug, cart_item).purchase_url}}' }}</code> for the URL</td>
				</tr>
				{% endif %}

				{% if member.login_url is defined %}
				<tr>
					<td>Login Link</td>
					<td><a href="{{member.login_url}}">Link to "Login"</a></td>
					<td>Use <code>{{ '{{craft.imatrix.member(slug).login_url}}' }}</code> for the URL</td>
				</tr>
				{% endif %}
			</tbody>
		</table>

		<h2>Raw data</h2>

		<p>These are the available variables when calling <code>{{ '{{craft.imatrix.member(slug)}}' }}</code></p>

		{% for key, data in member %}
			{% if loop.first %}<table>
				<thead>
					<tr>
						<th>Key</th>
						<th>Value</th>
						<th>Template code</th>
					</tr>
				</thead>
			{% endif %}

			<tr>
				<td>{{key}}</td>
				<td>{{data}}</td>
				<td><code>{{ '{{craft.imatrix.member(slug).' ~ key ~ '}}' }}</code></td>
			</tr>

			{% if loop.last %}
				</table>
			{% endif %}
		{% endfor %}

	{% else %}
		{% if member.no_results is defined %}
			<p>No results found for member with slug <code>{{slug}}</code></p>
		{% else %}
			<p>An error occurred. Read on.</p>
		{% endif %}
		<h2>Error message</h2>
		<p>{{member.error}}</p>
	{% endif %}

{% endblock %}